[jruby~main:d372c3ca] More tweaks for native Delegator impl.

  • From: nicksieger@kenai.com
  • To: commits@jruby.kenai.com
  • Subject: [jruby~main:d372c3ca] More tweaks for native Delegator impl.
  • Date: Fri, 19 Mar 2010 13:59:51 +0000

Project:    jruby
Repository: main
Revision:   d372c3ca0a292830212467b9760d92a198681ad3
Author:     nicksieger
Date:       2010-03-19 13:56:49 UTC
Link:       

Log Message:
------------
More tweaks for native Delegator impl.
* #respond_to? should check self first, for subclasses that introduce methods
* #method should check self first for the same reason


Revisions:
----------
d372c3ca0a292830212467b9760d92a198681ad3


Modified Paths:
---------------
src/org/jruby/ext/DelegateLibrary.java


Diffs:
------
diff --git a/src/org/jruby/ext/DelegateLibrary.java 
b/src/org/jruby/ext/DelegateLibrary.java
index 9200140..2500c27 100644
--- a/src/org/jruby/ext/DelegateLibrary.java
+++ b/src/org/jruby/ext/DelegateLibrary.java
@@ -6,6 +6,7 @@ import org.jruby.RubyMethod;
 import org.jruby.RubyModule;
 import org.jruby.RubyObject;
 import org.jruby.anno.JRubyMethod;
+import org.jruby.exceptions.RaiseException;
 import org.jruby.internal.runtime.methods.DynamicMethod;
 import org.jruby.internal.runtime.methods.JavaMethod.JavaMethodNBlock;
 import org.jruby.runtime.Block;
@@ -55,6 +56,12 @@ public class DelegateLibrary implements Library{
         public static IRubyObject method(ThreadContext context, IRubyObject 
self, IRubyObject name) {
             final String methodName = name.asJavaString();
             final IRubyObject object = self.callMethod(context, 
"__getobj__");
+
+            // try to get method from self, falling back on delegated object
+            if (self.respondsTo(methodName)) {
+                return (RubyMethod)((RubyObject)self).method(name);
+            }
+
             final RubyMethod method = 
(RubyMethod)((RubyObject)object).method(name);
             return RubyMethod.newMethod(self.getMetaClass(), methodName, 
self.getMetaClass(), methodName, new JavaMethodNBlock(self.getMetaClass(), 
Visibility.PUBLIC) {
                 @Override
@@ -69,6 +76,7 @@ public class DelegateLibrary implements Library{
 
         @JRubyMethod(name = "respond_to?")
         public static IRubyObject repond_to_p(ThreadContext context, 
IRubyObject self, IRubyObject name) {
+            if (self.getMetaClass().isMethodBound(name.asJavaString(), 
false)) return context.getRuntime().getTrue();
             return ((RubyObject)self.callMethod(context, 
"__getobj__")).callMethod(context, "respond_to?", name);
         }




[jruby~main:d372c3ca] More tweaks for native Delegator impl.

nicksieger 03/19/2010
  • Mysql
  • Glassfish
  • Jruby
  • Rails
  • Nblogo
Terms of Use; Privacy Policy;
© 2010, Oracle Corporation and/or its affiliates
(revision 20120127.ac94057)
 
 
Close
loading
Please Confirm
Close