[]=(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
/*
* call-seq:
* hsh[key] = value => value
* hsh.store(key, value) => value
*
* Element Assignment---Associates the value given by
* <i>value</i> with the key given by <i>key</i>.
* <i>key</i> should not have its value changed while it is in
* use as a key (a <code>String</code> passed as a key will be
* duplicated and frozen).
*
* h = { "a" => 100, "b" => 200 }
* h["a"] = 9
* h["c"] = 4
* h #=> {"a"=>9, "b"=>200, "c"=>4}
*
*/
VALUE
rb_hash_aset(hash, key, val)
VALUE hash, key, val;
{
rb_hash_modify(hash);
if (TYPE(key) != T_STRING || st_lookup(RHASH(hash)->tbl, key, 0)) {
st_insert(RHASH(hash)->tbl, key, val);
}
else {
st_add_direct(RHASH(hash)->tbl, rb_str_new4(key), val);
}
return val;
}