summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormarcandre <marcandre@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-11-06 17:12:20 +0000
committermarcandre <marcandre@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-11-06 17:12:20 +0000
commit727024fbac6ac97a3c4236583e5819d72a1513b7 (patch)
tree41159d5b62a79e1960b90d92eeda875fab886ebf
parentb8b01ab995b963db825b9b493aa98500f0be83e0 (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.rb4
-rw-r--r--vm_eval.c7
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
diff --git a/vm_eval.c b/vm_eval.c
index 756e49bdf4..8536282ebf 100644
--- a/vm_eval.c
+++ b/vm_eval.c
@@ -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 */
}