Skip to content

Commit

Permalink
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/RubyKernel.java
Original file line number Diff line number Diff line change
@@ -1295,7 +1295,7 @@ public static IRubyObject loop(ThreadContext context, IRubyObject recv, Block bl
final RubyClass StopIteration = runtime.getStopIteration();
if ( StopIteration.isInstance(ex.getException()) ) {
runtime.getGlobalVariables().set("$!", oldExc); // Restore $!
return context.nil;
return ex.getException().callMethod("result");
}
else {
throw ex;
7 changes: 7 additions & 0 deletions test/mri/ruby/test_enumerator.rb
Original file line number Diff line number Diff line change
@@ -47,6 +47,13 @@ def test_loop
}
end

def test_loop_return_value
assert_equal nil, loop { break }
assert_equal 42, loop { break 42 }
e = Enumerator.new { |y| y << 1; y << 2; :stopped }
assert_equal :stopped, loop { e.next while true }
end

def test_nested_iteration
def (o = Object.new).each
yield :ok1

0 comments on commit fccf3a5

Please sign in to comment.