instance method
Kernel#Hash
[K, V] (nil | [ ] _empty) -> ::Hash[K, V]
[K, V] (::hash[K, V] hash_like) -> ::Hash[K, V]
Hash(object) → object or new_hash
object.c
View on GitHub ↗
static VALUE
rb_f_hash(VALUE obj, VALUE arg)
{
return rb_Hash(arg);
}
Returns a hash converted from object.
-
If
objectis:-
A hash, returns
object. -
An empty array or
nil, returns an empty hash.
-
-
Otherwise, if
object.to_hashreturns a hash, returns that hash. -
Otherwise, returns
TypeError.
Examples:
Example
Hash({foo: 0, bar: 1}) # => {:foo=>0, :bar=>1} Hash(nil) # => {} Hash([]) # => {}