Skip to content

Commit

Permalink
Pass the correct arity to #each in Enumerable#find_index.
Browse files Browse the repository at this point in the history
  • Loading branch information
sluukkonen committed Feb 13, 2013
1 parent 34f2288 commit b38990d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
@@ -0,0 +1,7 @@
require 'rspec'

describe 'Enumerator#find_index' do
it 'should pass the correct number of arguments to the block' do
Enumerator.new { |y| y.yield :success }.find_index { |e| e == :success }.should == 0
end
end
4 changes: 2 additions & 2 deletions src/org/jruby/RubyEnumerable.java
Expand Up @@ -598,7 +598,7 @@ public static IRubyObject find_indexCommon(ThreadContext context, IRubyObject se
final long result[] = new long[] {0};

try {
callEach(runtime, context, self, Arity.NO_ARGUMENTS, new BlockCallback() {
callEach(runtime, context, self, Arity.ONE_ARGUMENT, new BlockCallback() {
public IRubyObject call(ThreadContext ctx, IRubyObject[] largs, Block blk) {
IRubyObject larg = checkArgs(runtime, largs);
if (block.yield(ctx, larg).isTrue()) throw JumpException.SPECIAL_JUMP;
Expand All @@ -609,7 +609,7 @@ public IRubyObject call(ThreadContext ctx, IRubyObject[] largs, Block blk) {
} catch (JumpException.SpecialJump sj) {
return RubyFixnum.newFixnum(runtime, result[0]);
}

return runtime.getNil();
}

Expand Down

0 comments on commit b38990d

Please sign in to comment.