[]=(p1, p2)
public
Element Assignment—Associates the
value given by value with the key
given by key. key should not have its value changed while
it is in use as a key (a String passed as a key
will be duplicated and frozen).
h = { "a" => 100, "b" => 200 }
h["a"] = 9
h["c"] = 4
h
Show source
VALUE
rb_hash_aset(VALUE hash, VALUE key, VALUE val)
{
rb_hash_modify(hash);
if (RHASH(hash)->ntbl->type == &identhash ||
TYPE(key) != T_STRING || st_lookup(RHASH(hash)->ntbl, key, 0)) {
st_insert(RHASH(hash)->ntbl, key, val);
}
else {
st_add_direct(RHASH(hash)->ntbl, rb_str_new4(key), val);
}
return val;
}