[](p1)
public
Element Reference—Retrieves the
value object corresponding to the key object. If not found, returns the default value (see Hash::new for details).
h = { "a" => 100, "b" => 200 }
h["a"]
h["c"]
Show source
VALUE
rb_hash_aref(VALUE hash, VALUE key)
{
st_data_t val;
if (RHASH_AR_TABLE_P(hash) && ar_lookup(hash, key, &val)) {
return (VALUE)val;
}
else if (RHASH_ST_TABLE_P(hash) && st_lookup(RHASH_ST_TABLE(hash), key, &val)) {
return (VALUE)val;
}
hash_verify(hash);
return rb_hash_default_value(hash, key);
}