jmtd → log → geek → code → ruby → Ruby Array to Hash
Here's a sick technique to convert an array-of-tuples into a Hash, in ruby:
> a = [["banana","yellow"],["tomato","red"]]
=> [["banana", "yellow"], ["tomato", "red"]]
> h = Hash[*a.flatten]
=> {"banana"=>"yellow", "tomato"=>"red"}
Comments