Skip to content

Commit

Permalink
Showing 3 changed files with 18 additions and 23 deletions.
16 changes: 5 additions & 11 deletions core/src/main/java/org/jruby/RubyGenerator.java
Original file line number Diff line number Diff line change
@@ -60,7 +60,7 @@ public RubyGenerator(Ruby runtime, RubyClass klass) {
public IRubyObject initialize(ThreadContext context, IRubyObject[] args, Block block) {
Ruby runtime = context.runtime;

IRubyObject proc;
final IRubyObject proc;

if (args.length == 0) {
proc = RubyProc.newProc(runtime, block, Block.Type.PROC);
@@ -76,7 +76,9 @@ public IRubyObject initialize(ThreadContext context, IRubyObject[] args, Block b
}
}

return init(runtime, proc);
// generator_init
this.proc = proc;
return this;
}

// generator_init_copy
@@ -96,15 +98,7 @@ public IRubyObject initialize_copy(ThreadContext context, IRubyObject other) {
// generator_each
@JRubyMethod(rest = true)
public IRubyObject each(ThreadContext context, IRubyObject[] args, Block block) {
return ((RubyProc) proc).call19(context, ArraySupport.newCopy(RubyYielder.newYielder(context, block), args), Block.NULL_BLOCK);
}


// generator_init
private IRubyObject init(Ruby runtime, IRubyObject proc) {
this.proc = proc;

return this;
return ((RubyProc) proc).call(context, ArraySupport.newCopy(RubyYielder.newYielder(context, block), args), Block.NULL_BLOCK);
}

private IRubyObject proc;
23 changes: 12 additions & 11 deletions core/src/main/java/org/jruby/RubyProc.java
Original file line number Diff line number Diff line change
@@ -238,14 +238,6 @@ public IRubyObject binding() {
return getRuntime().newBinding(block.getBinding());
}

public IRubyObject call(ThreadContext context, IRubyObject[] args, Block block) {
return call19(context, args, block);
}

public IRubyObject call(ThreadContext context, IRubyObject[] args) {
return call(context, args, null, Block.NULL_BLOCK);
}

/**
* For Type.LAMBDA, ensures that the args have the correct arity.
*
@@ -267,13 +259,17 @@ public static IRubyObject[] prepareArgs(ThreadContext context, Block.Type type,
}

@JRubyMethod(name = {"call", "[]", "yield", "==="}, rest = true, omit = true)
public final IRubyObject call19(ThreadContext context, IRubyObject[] args, Block blockCallArg) {
public final IRubyObject call(ThreadContext context, IRubyObject[] args, Block blockCallArg) {
IRubyObject[] preppedArgs = prepareArgs(context, type, block.getBody(), args);

return call(context, preppedArgs, null, blockCallArg);
}

public IRubyObject call(ThreadContext context, IRubyObject[] args, IRubyObject self, Block passedBlock) {
public final IRubyObject call(ThreadContext context, IRubyObject[] args) {
return call(context, args, null, Block.NULL_BLOCK);
}

public final IRubyObject call(ThreadContext context, IRubyObject[] args, IRubyObject self, Block passedBlock) {
assert args != null;

Block newBlock;
@@ -315,7 +311,7 @@ public IRubyObject source_location(ThreadContext context) {
runtime.newFixnum(binding.getLine() + 1 /*zero-based*/));
}

return runtime.getNil();
return context.nil;
}

@JRubyMethod
@@ -343,4 +339,9 @@ private boolean isThread() {
return type.equals(Block.Type.THREAD);
}

@Deprecated
public final IRubyObject call19(ThreadContext context, IRubyObject[] args, Block block) {
return call(context, args, block);
}

}
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/RubyYielder.java
Original file line number Diff line number Diff line change
@@ -99,7 +99,7 @@ public IRubyObject initialize(ThreadContext context, Block block) {
@JRubyMethod(rest = true)
public IRubyObject yield(ThreadContext context, IRubyObject[]args) {
checkInit();
return proc.call19(context, args, Block.NULL_BLOCK);
return proc.call(context, args, Block.NULL_BLOCK);
}

@JRubyMethod(name = "<<", rest = true)

0 comments on commit 0aef857

Please sign in to comment.