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:

[View source]

3946
3947
3948
3949
3950
# File 'object.c', line 3946

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