Monthly Archives: January 2015

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 🙂


$ irb

2.2.0 :001 > Hash['key1', 'value1', 'key2', 5]

 => {"key1"=>"value1", "key2"=>5}

2.2.0 :002 > Hash['key1', 'value1', 'key2']

ArgumentError: odd number of arguments for Hash

Advertisements
Tagged ,