[](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
/*
* call-seq:
* hsh[key] => value
*
* Element Reference---Retrieves the <i>value</i> object corresponding
* to the <i>key</i> object. If not found, returns the a default value (see
* <code>Hash::new</code> for details).
*
* h = { "a" => 100, "b" => 200 }
* h["a"]
* h["c"]
*
*/
VALUE
rb_hash_aref(hash, key)
VALUE hash, key;
{
VALUE val;
if (!st_lookup(RHASH(hash)->tbl, key, &val)) {
return rb_funcall(hash, id_default, 1, key);
}
return val;
}