private static boolean isMethodDefinedOnObjectClass(Method method) { if (method == null) { return false; } if (method.getDeclaringClass().equals(Object.class)) { return true; } if (ReflectionUtils.isEqualsMethod(method) || ReflectionUtils.isHashCodeMethod(method) || ReflectionUtils.isToStringMethod(method) || AopUtils.isFinalizeMethod(method)) { return true; } return (method.getName().equals("clone") && method.getParameterTypes().length == 0); }
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { if (ReflectionUtils.isEqualsMethod(method)) { return (isProxyForSameRubyObject(args[0]) ? Boolean.TRUE : Boolean.FALSE); } else if (ReflectionUtils.isHashCodeMethod(method)) { return new Integer(this.rubyObject.hashCode()); } else if (ReflectionUtils.isToStringMethod(method)) { String toStringResult = this.rubyObject.toString(); if (!StringUtils.hasText(toStringResult)) { toStringResult = ObjectUtils.identityToString(this.rubyObject); } return "JRuby object [" + toStringResult + "]"; } try { IRubyObject[] rubyArgs = convertToRuby(args); IRubyObject rubyResult = this.rubyObject.callMethod(this.ruby.getCurrentContext(), method.getName(), rubyArgs); return convertFromRuby(rubyResult, method.getReturnType()); } catch (RaiseException ex) { throw new JRubyExecutionException(ex); } }