Skip to content

Commit

Permalink
Method procs should have block args appropriate to arity.
Browse files Browse the repository at this point in the history
Fixes #2632
  • Loading branch information
headius committed Mar 12, 2015
1 parent 4c2d934 commit 5433238
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
12 changes: 11 additions & 1 deletion core/src/main/java/org/jruby/RubyMethod.java
Expand Up @@ -189,7 +189,17 @@ public int getLine() {
return RubyMethod.this.getLine();
}
};
BlockBody body = CompiledBlockLight19.newCompiledBlockLight(method.getArity(), runtime.getStaticScopeFactory().getDummyScope(), callback, false, 0, JRubyLibrary.MethodExtensions.methodParameters(runtime, method));
int argumentType;
if (method.getArity().isFixed()) {
if (method.getArity().required() > 0) {
argumentType = BlockBody.MULTIPLE_ASSIGNMENT;
} else {
argumentType = BlockBody.ZERO_ARGS;
}
} else {
argumentType = BlockBody.MULTIPLE_ASSIGNMENT;
}
BlockBody body = CompiledBlockLight19.newCompiledBlockLight(method.getArity(), runtime.getStaticScopeFactory().getDummyScope(), callback, false, argumentType, JRubyLibrary.MethodExtensions.methodParameters(runtime, method));
Block b = new Block(body, context.currentBinding(receiver, Visibility.PUBLIC));

return RubyProc.newProc(runtime, b, Block.Type.LAMBDA);
Expand Down
@@ -0,0 +1,10 @@
describe "A proc created from a Method object" do
it "receives block arguments based on its arity" do
$GH2632 = nil
o = Object.new
def o.foo(a); $GH2632 = a; end
m = o.method :foo
(1..1).each &m
expect($GH2632).to eq(1)
end
end

0 comments on commit 5433238

Please sign in to comment.