Method: Kernel#Hash

Defined in:
object.c

#Hash(object) ⇒ Object

Returns a hash converted from object.

  • If object is:

    • A hash, returns object.

    • An empty array or nil, returns an empty hash.

  • Otherwise, if object.to_hash returns a hash, returns that hash.

  • Otherwise, returns TypeError.

Examples:

Hash({foo: 0, bar: 1}) # => {:foo=>0, :bar=>1}
Hash(nil)              # => {}
Hash([])               # => {}

Returns:



3921
3922
3923
3924
3925
# File 'object.c', line 3921

static VALUE
rb_f_hash(VALUE obj, VALUE arg)
{
    return rb_Hash(arg);
}