/** * Check if the method has a custom respond_to? and call it if so with the method ID we're hoping to call. * * MRI: check_funcall_respond_to */ private static boolean checkFuncallRespondTo(ThreadContext context, RubyClass klass, IRubyObject recv, RespondToCallSite respondToSite) { final Ruby runtime = context.runtime; DynamicMethod me = respondToSite.retrieveCache(klass).method; // NOTE: isBuiltin here would be NOEX_BASIC in MRI, a flag only added to respond_to?, method_missing, and // respond_to_missing? Same effect, I believe. if (me != null && !me.isUndefined() && !me.isBuiltin()) { int arityValue = me.getArity().getValue(); if (arityValue > 2) throw runtime.newArgumentError("respond_to? must accept 1 or 2 arguments (requires " + arityValue + ")"); boolean result; if (arityValue == 1) { result = respondToSite.respondsTo(context, recv, recv); } else { result = respondToSite.respondsTo(context, recv, recv, true); } return result; } return true; }
/** * Check if the method has a custom respond_to? and call it if so with the method ID we're hoping to call. * * MRI: check_funcall_respond_to */ private static boolean checkFuncallRespondTo(ThreadContext context, RubyClass klass, IRubyObject recv, RespondToCallSite respondToSite) { final Ruby runtime = context.runtime; DynamicMethod me = respondToSite.retrieveCache(klass).method; // NOTE: isBuiltin here would be NOEX_BASIC in MRI, a flag only added to respond_to?, method_missing, and // respond_to_missing? Same effect, I believe. if (me != null && !me.isUndefined() && !me.isBuiltin()) { int arityValue = me.getArity().getValue(); if (arityValue > 2) throw runtime.newArgumentError("respond_to? must accept 1 or 2 arguments (requires " + arityValue + ")"); boolean result; if (arityValue == 1) { result = respondToSite.respondsTo(context, recv, recv); } else { result = respondToSite.respondsTo(context, recv, recv, true); } return result; } return true; }