/* * call-seq: * hsh.default = obj => hsh * * Sets the default value, the value returned for a key that does not * exist in the hash. It is not possible to set the a default to a * <code>Proc</code> that will be executed on each key lookup. * * h = { "a" => 100, "b" => 200 } * h.default = "Go fish" * h["a"] #=> 100 * h["z"] #=> "Go fish" * # This doesn't do what you might hope... * h.default = proc do |hash, key| * hash[key] = key + key * end * h[2] #=> #<Proc:0x401b3948@-:6> * h["cat"] #=> #<Proc:0x401b3948@-:6> */ static VALUE rb_hash_set_default(hash, ifnone) VALUE hash, ifnone; { rb_hash_modify(hash); RHASH(hash)->ifnone = ifnone; FL_UNSET(hash, HASH_PROC_DEFAULT); return ifnone; }