Project

General

Profile

Feature #4234 ยป hash-default-proc.patch

runpaint (Run Paint Run Run), 01/06/2011 01:11 AM

View differences:

hash.c
VALUE b;
rb_hash_modify(hash);
if (NIL_P(proc)) {
FL_UNSET(hash, HASH_PROC_DEFAULT);
RHASH_IFNONE(hash) = proc;
return proc;
}
b = rb_check_convert_type(proc, T_DATA, "Proc", "to_proc");
if (NIL_P(b) || !rb_obj_is_proc(b)) {
rb_raise(rb_eTypeError,
test/ruby/test_hash.rb
def test_default_proc
h = Hash.new {|hh, k| hh + k + "baz" }
assert_equal("foobarbaz", h.default_proc.call("foo", "bar"))
assert_nil(h.default_proc = nil)
assert_nil(h.default_proc)
h.default_proc = ->(h, k){ true }
assert(h[:nope])
h = {}
assert_nil(h.default_proc)
end
    (1-1/1)