diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-05-14 11:45:00 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-05-14 11:45:00 +0000 |
commit | e0c94f70da76d45945e08dea1359add4486c6de5 (patch) | |
tree | 2c972cea1aa44ce2699460c5e89be466bc732854 | |
parent | 95590be3b1adbf1873f6c4feb2f4d21d49bd0d36 (diff) | |
download | ruby-e0c94f70da76d45945e08dea1359add4486c6de5.tar.gz |
object.c: use a sized enumerator with #yield_self
* object.c (rb_obj_size): The #yield_self Enumerator instance
always has a #count of `1`. This provides a lazy #size of `1`
to match the count instead of `nil`. [Fix GH-1615]
Author: Shannon Skipper <shannonskipper@gmail.com>
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58714 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | object.c | 8 | ||||
-rw-r--r-- | test/ruby/test_object.rb | 4 |
2 files changed, 10 insertions, 2 deletions
@@ -497,6 +497,12 @@ rb_obj_itself(VALUE obj) return obj; } +static VALUE +rb_obj_size(VALUE self, VALUE args, VALUE obj) +{ + return LONG2FIX(1); +} + /* * call-seq: * obj.yield_self {|_obj|...} -> an_object @@ -510,7 +516,7 @@ rb_obj_itself(VALUE obj) static VALUE rb_obj_yield_self(VALUE obj) { - RETURN_ENUMERATOR(obj, 0, 0); + RETURN_SIZED_ENUMERATOR(obj, 0, 0, rb_obj_size); return rb_yield_values2(1, &obj); } diff --git a/test/ruby/test_object.rb b/test/ruby/test_object.rb index 6a1a82546a..1e952533a6 100644 --- a/test/ruby/test_object.rb +++ b/test/ruby/test_object.rb @@ -23,7 +23,9 @@ class TestObject < Test::Unit::TestCase object = Object.new assert_same(self, object.yield_self {self}, feature) assert_same(object, object.yield_self {|x| break x}, feature) - assert_instance_of(Enumerator, object.yield_self) + enum = object.yield_self + assert_instance_of(Enumerator, enum) + assert_equal(1, enum.size) end def test_dup |