diff options
Diffstat (limited to 'hash.c')
-rw-r--r-- | hash.c | 14 |
1 files changed, 9 insertions, 5 deletions
@@ -66,7 +66,7 @@ rb_hash_freeze(VALUE hash) VALUE rb_cHash; static VALUE envtbl; -static ID id_hash, id_yield, id_default; +static ID id_hash, id_yield, id_default, id_flatten_bang; VALUE rb_hash_set_ifnone(VALUE hash, VALUE ifnone) @@ -2377,10 +2377,13 @@ rb_hash_flatten(int argc, VALUE *argv, VALUE hash) ary = rb_ary_new_capa(RHASH_SIZE(hash) * 2); rb_hash_foreach(hash, flatten_i, ary); if (argc) { - int level = NUM2INT(*argv) - 1; - if (level > 0) { - *argv = INT2FIX(level); - rb_funcall2(ary, rb_intern("flatten!"), argc, argv); + int level = NUM2INT(*argv); + if (level - 1 > 0) { + *argv = INT2FIX(level - 1); + rb_funcall2(ary, id_flatten_bang, argc, argv); + } + else if (level == -1) { + rb_funcall2(ary, id_flatten_bang, 0, 0); } } return ary; @@ -3732,6 +3735,7 @@ Init_Hash(void) id_hash = rb_intern("hash"); id_yield = rb_intern("yield"); id_default = rb_intern("default"); + id_flatten_bang = rb_intern("flatten!"); rb_cHash = rb_define_class("Hash", rb_cObject); |