Permalink
Browse files

Pass the correct arity to #each in Enumerable#find_index.

  • Loading branch information...
1 parent 1f3c0df commit de1abd097168021995f27c5e8acbc25ceefc281c @sluukkonen sluukkonen committed with BanzaiMan Feb 13, 2013
@@ -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
@@ -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;
@@ -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();
}

0 comments on commit de1abd0

Please sign in to comment.