Gemfile · I codes and I blogs

Hash[ ]

Calling the [] method on Hash converts a one-dimensional array with an even number of elements into a hash, with odd/even elements alternating as keys/values. Very cool

2.2.0 :001 > Hash['key1', 'value1', 'key2', 5]
 => {"key1"=>"value1", "key2"=>5}
2.2.0 :002 > Hash['k1', 'v1', 'k2']
 => ArgumentError: odd number of arguments for Hash