ruby-changes:25449
From: marcandre <ko1@a...>
Date: Wed, 7 Nov 2012 02:12:29 +0900 (JST)
Subject: [ruby-changes:25449] marcandRe: r37506 (trunk): * vm_eval.c (rb_f_loop): Support for loop.size
marcandre 2012-11-07 02:12:20 +0900 (Wed, 07 Nov 2012) New Revision: 37506 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=37506 Log: * vm_eval.c (rb_f_loop): Support for loop.size [Feature #6636] Modified files: trunk/test/ruby/test_enumerator.rb trunk/vm_eval.c Index: vm_eval.c =================================================================== --- vm_eval.c (revision 37505) +++ vm_eval.c (revision 37506) @@ -920,6 +920,11 @@ return Qnil; } +static VALUE +rb_f_loop_size(VALUE self, VALUE args) { + return DBL2NUM(INFINITY); +} + /* * call-seq: * loop { block } @@ -942,7 +947,7 @@ 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 */ } Index: test/ruby/test_enumerator.rb =================================================================== --- test/ruby/test_enumerator.rb (revision 37505) +++ test/ruby/test_enumerator.rb (revision 37506) @@ -464,5 +464,9 @@ 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 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/