Ruby Newbie homepage Ruby Newbie homepage

How to use

Quick guide

Official content
Returns the value associated with the given key, if found:
h = {foo: 0, bar: 1, baz: 2}
h[:foo] # => 0
If key is not found, returns a default value (see Default Values):
h = {foo: 0, bar: 1, baz: 2}
h[:nosuch] # => nil
 
               VALUE
rb_hash_aref(VALUE hash, VALUE key)
{
    st_data_t val;

    if (hash_stlike_lookup(hash, key, &val)) {
        return (VALUE)val;
    }
    else {
        return rb_hash_default_value(hash, key);
    }
}
            

Was this page useful?