Convert Ruby array of tuples into a hash given an array of keys?
Posted
by
Kit Ho
on Stack Overflow
See other posts from Stack Overflow
or by Kit Ho
Published on 2012-06-08T04:13:39Z
Indexed on
2012/06/08
4:40 UTC
Read the original article
Hit count: 282
I have an simple array
array = ["apple", "orange", "lemon"]
array2 = [["apple", "good taste", "red"], ["orange", "bad taste", "orange"], ["lemon" , "no taste", "yellow"]]
how can i convert in to this hash whenever element in array match the first element of each element in array2?
hash = {"apple" => ["apple" ,"good taste", "red"],
"orange" => ["orange", "bad taste", "orange"],
"lemon" => ["lemon" , "no taste", "yellow"] }
I am quite new to ruby, and spend a lot to do this manipulation, but no luck, any help ?
© Stack Overflow or respective owner