1 28 package org.jruby.runtime; 29 30 import org.jruby.RubyModule; 31 import org.jruby.internal.runtime.methods.AbstractCallable; 32 import org.jruby.runtime.builtin.IRubyObject; 33 34 39 public class CallBlock extends Block { 40 private Arity arity; 41 private BlockCallback callback; 42 private IRubyObject self; 43 private RubyModule imClass; 44 private ThreadContext tc; 45 46 public CallBlock(IRubyObject self, RubyModule imClass, Arity arity, BlockCallback callback, ThreadContext ctx) { 47 super(null, 48 new CallMethod(callback), 49 self, 50 ctx.getCurrentFrame(), 51 ctx.peekCRef(), 52 Visibility.PUBLIC, 53 ctx.getRubyClass(), 54 ctx.getCurrentScope()); 55 this.arity = arity; 56 this.callback = callback; 57 this.self = self; 58 this.imClass = imClass; 59 this.tc = ctx; 60 } 61 62 public IRubyObject call(ThreadContext context, IRubyObject[] args, IRubyObject replacementSelf) { 63 return callback.call(context, args, replacementSelf, Block.NULL_BLOCK); 64 } 65 66 public Block cloneBlock() { 67 return new CallBlock(self,imClass,arity,callback,tc); 68 } 69 70 public Arity arity() { 71 return arity; 72 } 73 74 public static class CallMethod extends AbstractCallable { 75 private BlockCallback callback; 76 public CallMethod(BlockCallback callback) { 77 this.callback = callback; 78 } 79 80 public IRubyObject call(ThreadContext context, IRubyObject receiver, IRubyObject[] args, Block block) { 81 return callback.call(context, args,receiver, block); 82 } 83 84 public ICallable dup() { 85 return new CallMethod(callback); 86 } 87 } 88 } 89 | Popular Tags |