method

[]

v1_8_7_72 - Show latest stable - Class: Hash
[](...)
public

Creates a new hash populated with the given objects. Equivalent to the literal { key, value, ... }. Keys and values occur in pairs, so there must be an even number of arguments.

   Hash["a", 100, "b", 200]       #=> {"a"=>100, "b"=>200}
   Hash["a" => 100, "b" => 200]   #=> {"a"=>100, "b"=>200}
   { "a" => 100, "b" => 200 }     #=> {"a"=>100, "b"=>200}

2Notes

Assignment using 'key: value'

UnfalseIdeas · Jul 19, 2012

Another shorthand way of assigning key, value pairs:

Hash[one: 1, two: 2] #=> {:one=>1, :two=>2}

@UnfalseIdeas

pascal · Apr 17, 2013

What is the purpose of

Hash[one: 1, two: 1]

When you can write

{one: 1, two: 2}

Aren't you just passing a hash into the [] method?