APIdock / Ruby
/
method

hash

ruby latest stable - Class: Object

Method deprecated or moved

This method is deprecated or moved on the latest stable version. The last existing version (v2_4_6) is shown here.

hash()
protected

Generates an Integer hash value for this object. This function must have the property that a.eql?(b) implies a.hash == b.hash.

The hash value is used along with #eql? by the Hash class to determine if two objects reference the same hash key. Any hash value that exceeds the capacity of an Integer will be truncated before being used.

The hash value for an object may not be identical across invocations or implementations of Ruby. If you need a stable identifier across Ruby invocations and implementations you will need to generate one with a custom method.

VALUE
rb_obj_hash(VALUE obj)
{
 VALUE oid = rb_obj_id(obj);
#if SIZEOF_LONG == SIZEOF_VOIDP
 st_index_t index = NUM2LONG(oid);
#elif SIZEOF_LONG_LONG == SIZEOF_VOIDP
 st_index_t index = NUM2LL(oid);
#else
# error not supported
#endif
 return LONG2FIX(rb_objid_hash(index));
}

AltStyle によって変換されたページ (->オリジナル) /