[](p1)
public
Element Reference—Retrieves the
value object corresponding to the key object. If not found, returns the a 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)
{
VALUE val;
if (!RHASH(hash)->ntbl || !st_lookup(RHASH(hash)->ntbl, key, &val)) {
return rb_funcall(hash, id_default, 1, key);
}
return val;
}