method
default
ruby latest stable - Class:
Hash
default(*args)public
Returns the default value, the value that would be returned by hsh[key] if key did not exist in hsh. See also Hash::new and Hash#default=.
h = Hash .new #=> {} h.default #=> nil h.default (2) #=> nil h = Hash .new ("cat") #=> {} h.default #=> "cat" h.default (2) #=> "cat" h = Hash .new {|h,k| h[k] = k.to_i*10} #=> {} h.default #=> nil h.default (2) #=> 20
static VALUE
rb_hash_default(int argc, VALUE *argv, VALUE hash)
{
VALUE args[2], ifnone;
rb_check_arity(argc, 0, 1);
ifnone = RHASH_IFNONE(hash);
if (FL_TEST(hash, HASH_PROC_DEFAULT)) {
if (argc == 0) return Qnil;
args[0] = hash;
args[1] = argv[0];
return rb_funcallv(ifnone, id_yield, 2, args);
}
return ifnone;
}