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 ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: