* 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
This commit is contained in:
parent
b8b01ab995
commit
727024fbac
@ -464,5 +464,9 @@ class TestEnumerator < Test::Unit::TestCase
|
|||||||
assert_equal 0, [].cycle.size
|
assert_equal 0, [].cycle.size
|
||||||
assert_equal 0, [].cycle(5).size
|
assert_equal 0, [].cycle(5).size
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_size_for_loops
|
||||||
|
assert_equal Float::INFINITY, loop.size
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -920,6 +920,11 @@ loop_i(void)
|
|||||||
return Qnil;
|
return Qnil;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static VALUE
|
||||||
|
rb_f_loop_size(VALUE self, VALUE args) {
|
||||||
|
return DBL2NUM(INFINITY);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* call-seq:
|
* call-seq:
|
||||||
* loop { block }
|
* loop { block }
|
||||||
@ -942,7 +947,7 @@ loop_i(void)
|
|||||||
static VALUE
|
static VALUE
|
||||||
rb_f_loop(VALUE self)
|
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);
|
rb_rescue2(loop_i, (VALUE)0, 0, 0, rb_eStopIteration, (VALUE)0);
|
||||||
return Qnil; /* dummy */
|
return Qnil; /* dummy */
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user