method
[]

[](*args)
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}
Register or
log in
to add new notes.
UnfalseIdeas -
July 19, 2012
pascal -
April 17, 2013

0 thanks
Assignment using 'key: value'
Another shorthand way of assigning key, value pairs:
Hash[one: 1, two: 2] #=> {:one=>1, :two=>2}

0 thanks
@UnfalseIdeas
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?