Reputation: 693
I see many seemingly interchangeable ways to create a hash. The following all create the same hash:
w = {:one => 1, :two => 2}
x = Hash[:one => 1, :two => 2]
y = Hash.[](:one => 1, :two => 2)
z = Hash.send(:[], :one => 1, :two => 2)
huh = Hash(:one => 1, :two => 2)
As for Hash(:one => 1, :two => 2)
, I expect to find a :()
method for Hash
in the documentation. Along with the documented method ::[]
, shouldn't the documentation also list a ::()
method?
If they are both just syntactic sugar, where is the latter method documented?
Upvotes: 2
Views: 64
Reputation: 36101
It's a method in Kernel
(which contains other methods that you can call directly like Kernel.puts
) - Kernel.Hash
. Don't use it (it's not idiomatic).
Upvotes: 3