Convert Ruby array of tuples into a hash given an array of keys?
- by Kit Ho
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 ?