| Method from org.jruby.RubyMethod Detail: |
public RubyFixnum arity() {
return getRuntime().newFixnum(method.getArity().getValue());
}
Returns the number of arguments a method accepted. |
public static IRubyObject bmcall(IRubyObject blockArg,
IRubyObject arg1,
IRubyObject self,
Block unusedBlock) {
ThreadContext context = blockArg.getRuntime().getCurrentContext();
if (blockArg instanceof RubyArray) {
// ENEBO: Very wrong
return ((RubyMethod) arg1).call(context, ((RubyArray) blockArg).toJavaArray(), Block.NULL_BLOCK);
}
// ENEBO: Very wrong
return ((RubyMethod) arg1).call(context, new IRubyObject[] { blockArg }, Block.NULL_BLOCK);
}
Delegate a block call to a bound method call.
Used by the RubyMethod#to_proc method. |
public IRubyObject call(ThreadContext context,
IRubyObject[] args,
Block block) {
assert args != null;
method.getArity().checkArity(context.getRuntime(), args);
// FIXME: should lastClass be implementation module for a Method?
return method.call(context, receiver, implementationModule, methodName, args, block);
}
|
public static RubyClass createMethodClass(Ruby runtime) {
// TODO: NOT_ALLOCATABLE_ALLOCATOR is probably ok here. Confirm. JRUBY-415
RubyClass methodClass = runtime.defineClass("Method", runtime.getObject(), ObjectAllocator.NOT_ALLOCATABLE_ALLOCATOR);
runtime.setMethod(methodClass);
methodClass.defineAnnotatedMethods(RubyMethod.class);
return methodClass;
}
Create the RubyMethod class and add it to the Ruby runtime. |
public IRubyObject inspect() {
StringBuilder buf = new StringBuilder("#< ");
char delimeter = '#";
buf.append(getMetaClass().getRealClass().getName()).append(": ");
if (implementationModule.isSingleton()) {
IRubyObject attached = ((MetaClass) implementationModule).getAttached();
if (receiver == null) {
buf.append(implementationModule.inspect().toString());
} else if (receiver == attached) {
buf.append(attached.inspect().toString());
delimeter = '.";
} else {
buf.append(receiver.inspect().toString());
buf.append('(").append(attached.inspect().toString()).append(')");
delimeter = '.";
}
} else {
buf.append(originModule.getName());
if (implementationModule != originModule) {
buf.append('(").append(implementationModule.getName()).append(')");
}
}
buf.append(delimeter).append(methodName).append(' >");
RubyString str = getRuntime().newString(buf.toString());
str.setTaint(isTaint());
return str;
}
|
public static RubyMethod newMethod(RubyModule implementationModule,
String methodName,
RubyModule originModule,
String originName,
DynamicMethod method,
IRubyObject receiver) {
Ruby runtime = implementationModule.getRuntime();
RubyMethod newMethod = new RubyMethod(runtime, runtime.getMethod());
newMethod.implementationModule = implementationModule;
newMethod.methodName = methodName;
newMethod.originModule = originModule;
newMethod.originName = originName;
newMethod.method = method.getRealMethod();
newMethod.receiver = receiver;
return newMethod;
}
|
public RubyBoolean op_equal(ThreadContext context,
IRubyObject other) {
if (!(other instanceof RubyMethod)) return context.getRuntime().getFalse();
RubyMethod otherMethod = (RubyMethod)other;
return context.getRuntime().newBoolean(implementationModule == otherMethod.implementationModule &&
originModule == otherMethod.originModule &&
receiver == otherMethod.receiver &&
method.getRealMethod() == otherMethod.method.getRealMethod());
}
|
public RubyMethod rbClone() {
return newMethod(implementationModule, methodName, originModule, originName, method, receiver);
}
|
public IRubyObject to_proc(ThreadContext context,
Block unusedBlock) {
Ruby runtime = context.getRuntime();
CallbackFactory f = runtime.callbackFactory(RubyMethod.class);
Block block = MethodBlock.createMethodBlock(context, context.getCurrentScope(),
f.getBlockMethod("bmcall"), this, runtime.getTopSelf());
while (true) {
try {
// FIXME: We should not be regenerating this over and over
return mproc(context, block);
} catch (JumpException.BreakJump bj) {
return (IRubyObject) bj.getValue();
} catch (JumpException.ReturnJump rj) {
return (IRubyObject) rj.getValue();
} catch (JumpException.RetryJump rj) {
// Execute iterateMethod again.
}
}
}
|
public RubyUnboundMethod unbind(Block unusedBlock) {
RubyUnboundMethod unboundMethod =
RubyUnboundMethod.newUnboundMethod(implementationModule, methodName, originModule, originName, method);
unboundMethod.infectBy(this);
return unboundMethod;
}
|