Feature #10498 » 0001-vm_eval.c-loop-now-yields-a-incremented-counter.patch
ChangeLog | ||
---|---|---|
Wed Nov 12 05:57:20 2014 Franck Verrot <franck@verrot.fr>
|
||
* vm_eval.c (loop_i): make loop yield a counter to
|
||
keep track of the iteration count.
|
||
Wed Nov 12 00:26:37 2014 Tanaka Akira <akr@fsij.org>
|
||
* test/ruby/test_object.rb: Specify an exception class for rescue clause.
|
test/ruby/test_enumerator.rb | ||
---|---|---|
}
|
||
end
|
||
def test_loop_yield
|
||
max = 0
|
||
loop do |i|
|
||
max = i
|
||
raise StopIteration if i >= 1
|
||
end
|
||
assert_equal 1, max
|
||
end
|
||
def test_nested_iteration
|
||
def (o = Object.new).each
|
||
yield :ok1
|
vm_eval.c | ||
---|---|---|
static VALUE
|
||
loop_i(void)
|
||
{
|
||
for (;;) {
|
||
rb_yield_0(0, 0);
|
||
}
|
||
return Qnil;
|
||
VALUE counter = INT2FIX(0);
|
||
VALUE increment = INT2FIX(1);
|
||
for (;;) {
|
||
rb_yield_values(1, counter);
|
||
counter = rb_funcall(counter, '+', 1, increment);
|
||
}
|
||
return Qnil;
|
||
}
|
||
static VALUE
|
- « Previous
- 1
- 2
- Next »