@JRubyMethod(required = 1, rest = true, omit = true)
public static IRubyObject method_missing(ThreadContext context, IRubyObject self, IRubyObject[] args, Block block) {
IRubyObject[] newArgs = new IRubyObject[args.length - 1];
System.arraycopy(args, 1, newArgs, 0, newArgs.length);
String methodName = args[0].asJavaString();
RubyBasicObject object = (RubyBasicObject)self.callMethod(context, "__getobj__");
DynamicMethod method = object.getMetaClass().searchMethod(methodName);
if (method.isUndefined()) {
// catch respond_to? and respond_to_missing? cases
if (object.callMethod(context, "respond_to?", args[0]).isTrue()) {
return object.callMethod(context, methodName, newArgs, block);
}
RubyKernel.methodMissing(context, self, methodName, Visibility.PUBLIC, CallType.FUNCTIONAL, newArgs, block);
} else if (method.getVisibility().isPrivate()) {
RubyKernel.methodMissing(context, self, methodName, Visibility.PRIVATE, CallType.FUNCTIONAL, newArgs, block);
}
return method.call(context, object, object.getMetaClass(), methodName, newArgs, block);
}