Skip to content

Commit

Permalink
lambda/proc with no args should see parent frames block. Added reads=…
Browse files Browse the repository at this point in the history
…BLOCK to lambda/proc/ AND Proc.new
  • Loading branch information
enebo committed Dec 13, 2016
1 parent f0c1124 commit ff06af4
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
10 changes: 8 additions & 2 deletions core/src/main/java/org/jruby/RubyKernel.java
Expand Up @@ -1268,13 +1268,19 @@ public static IRubyObject define_singleton_method(ThreadContext context, IRubyOb
}
}

@JRubyMethod(name = "proc", module = true, visibility = PRIVATE)
@JRubyMethod(name = "proc", module = true, visibility = PRIVATE, reads = BLOCK)
public static RubyProc proc(ThreadContext context, IRubyObject recv, Block block) {
// No passed in block, lets check next outer frame for one ('Proc.new')
if (!block.isGiven()) block = context.getCurrentFrame().getBlock();

return context.runtime.newProc(Block.Type.PROC, block);
}

@JRubyMethod(module = true, visibility = PRIVATE)
@JRubyMethod(module = true, visibility = PRIVATE, reads = BLOCK)
public static RubyProc lambda(ThreadContext context, IRubyObject recv, Block block) {
// No passed in block, lets check next outer frame for one ('Proc.new')
if (!block.isGiven()) block = context.getCurrentFrame().getBlock();

// If we encounter a amp'd proc we leave it a proc for some reason.
Block.Type type = block.type == Block.Type.PROC ? block.type : Block.Type.LAMBDA;

Expand Down
4 changes: 3 additions & 1 deletion core/src/main/java/org/jruby/RubyProc.java
Expand Up @@ -50,6 +50,8 @@
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.runtime.marshal.DataType;

import static org.jruby.anno.FrameField.BLOCK;

/**
* @author jpetersen
*/
Expand Down Expand Up @@ -136,7 +138,7 @@ public static RubyProc newProc(Ruby runtime, Block block, Block.Type type, Strin
* since we need to deal with special case of Proc.new with no arguments or block arg. In
* this case, we need to check previous frame for a block to consume.
*/
@JRubyMethod(name = "new", rest = true, meta = true)
@JRubyMethod(name = "new", rest = true, meta = true, reads = BLOCK)
public static IRubyObject newInstance(ThreadContext context, IRubyObject recv, IRubyObject[] args, Block block) {
// No passed in block, lets check next outer frame for one ('Proc.new')
if (!block.isGiven()) block = context.getCurrentFrame().getBlock();
Expand Down
1 change: 0 additions & 1 deletion spec/tags/ruby/language/lambda_tags.txt

This file was deleted.

0 comments on commit ff06af4

Please sign in to comment.