diff options
| -rw-r--r-- | mrbgems/mruby-enumerator/test/enumerator.rb | 8 | ||||
| -rw-r--r-- | mrblib/hash.rb | 4 | ||||
| -rw-r--r-- | src/string.c | 2 |
3 files changed, 13 insertions, 1 deletions
diff --git a/mrbgems/mruby-enumerator/test/enumerator.rb b/mrbgems/mruby-enumerator/test/enumerator.rb index c2b4c09ab..fdee06450 100644 --- a/mrbgems/mruby-enumerator/test/enumerator.rb +++ b/mrbgems/mruby-enumerator/test/enumerator.rb @@ -486,6 +486,14 @@ assert 'Hash#each' do assert_equal [[:a,1], [:b,2]], c.sort end +assert 'Hash#each_key' do + assert_equal [:a,:b], {a:1,b:2}.each_key.to_a.sort +end + +assert 'Hash#each_value' do + assert_equal [1,2], {a:1,b:2}.each_value.to_a.sort +end + assert 'Range#each' do a = (1..5) b = a.each diff --git a/mrblib/hash.rb b/mrblib/hash.rb index 0423f7edc..cd6ba8935 100644 --- a/mrblib/hash.rb +++ b/mrblib/hash.rb @@ -69,6 +69,8 @@ class Hash # # ISO 15.2.13.4.10 def each_key(&block) + return to_enum :each_key unless block_given? + self.keys.each{|k| block.call(k)} self end @@ -93,6 +95,8 @@ class Hash # # ISO 15.2.13.4.11 def each_value(&block) + return to_enum :each_value unless block_given? + self.keys.each{|k| block.call(self[k])} self end diff --git a/src/string.c b/src/string.c index 1b82802f9..648363a45 100644 --- a/src/string.c +++ b/src/string.c @@ -28,7 +28,6 @@ if (STR_EMBED_P(s)) {\ STR_SET_EMBED_LEN((s),(n));\ } else {\ - mrb_assert((n) <= MRB_INT_MAX);\ s->as.heap.len = (mrb_int)(n);\ }\ } while (0) @@ -273,6 +272,7 @@ str_buf_cat(mrb_state *mrb, struct RString *s, const char *ptr, size_t len) ptr = STR_PTR(s) + off; } memcpy(STR_PTR(s) + STR_LEN(s), ptr, len); + mrb_assert(total <= MRB_INT_MAX); STR_SET_LEN(s, total); STR_PTR(s)[total] = '\0'; /* sentinel */ } |
