diff options
author | marcandre <marcandre@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-11-06 17:12:20 +0000 |
---|---|---|
committer | marcandre <marcandre@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-11-06 17:12:20 +0000 |
commit | 727024fbac6ac97a3c4236583e5819d72a1513b7 (patch) | |
tree | 41159d5b62a79e1960b90d92eeda875fab886ebf | |
parent | b8b01ab995b963db825b9b493aa98500f0be83e0 (diff) |
* vm_eval.c (rb_f_loop): Support for loop.size
[Feature #6636]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37506 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | test/ruby/test_enumerator.rb | 4 | ||||
-rw-r--r-- | vm_eval.c | 7 |
2 files changed, 10 insertions, 1 deletions
diff --git a/test/ruby/test_enumerator.rb b/test/ruby/test_enumerator.rb index 49d7827d35..b2ef8e5c25 100644 --- a/test/ruby/test_enumerator.rb +++ b/test/ruby/test_enumerator.rb @@ -464,5 +464,9 @@ class TestEnumerator < Test::Unit::TestCase assert_equal 0, [].cycle.size assert_equal 0, [].cycle(5).size end + + def test_size_for_loops + assert_equal Float::INFINITY, loop.size + end end @@ -920,6 +920,11 @@ loop_i(void) return Qnil; } +static VALUE +rb_f_loop_size(VALUE self, VALUE args) { + return DBL2NUM(INFINITY); +} + /* * call-seq: * loop { block } @@ -942,7 +947,7 @@ loop_i(void) static VALUE rb_f_loop(VALUE self) { - RETURN_ENUMERATOR(self, 0, 0); + RETURN_SIZED_ENUMERATOR(self, 0, 0, rb_f_loop_size); rb_rescue2(loop_i, (VALUE)0, 0, 0, rb_eStopIteration, (VALUE)0); return Qnil; /* dummy */ } |