Ruby : Hash can have `Array` as key

Unlike other languages, In Ruby you can even have `Array` as `Key` to a Hash Object. This technique can be useful if you wish that the combination of two object maps to a value. 

hash = {[:controller, :action] => 'value'}
# => {[:controller, :action]=>"value"} 

> hash[[:controller,:value]]
# => nil 

> hash[[:controller,:action]]
# => "value" 

FYI: In Ruby you can have Array as a Key of a Hash object

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