/* * call-seq: * hsh.default(key=nil) => obj * * Returns the default value, the value that would be returned by * <i>hsh</i>[<i>key</i>] if <i>key</i> did not exist in <i>hsh</i>. * See also <code>Hash::new</code> and <code>Hash#default=</code>. * * 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 #=> 0 * h.default(2) #=> 20 */ static VALUE rb_hash_default(argc, argv, hash) int argc; VALUE *argv; VALUE hash; { VALUE key; rb_scan_args(argc, argv, "01", &key); if (FL_TEST(hash, HASH_PROC_DEFAULT)) { if (argc == 0) return Qnil; return rb_funcall(RHASH(hash)->ifnone, id_call, 2, hash, key); } return RHASH(hash)->ifnone; }