Details
-
Type:
Wish
-
Status:
Resolved
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: JRuby 1.6.7
-
Fix Version/s: JRuby 1.7.0.pre2
-
Component/s: Embedding, Java Integration
-
Labels:None
-
Number of attachments :
Description
We are doing something like this:
import org.jruby.embed.ScriptingContainer;
import java.util.Arrays;
class MethodsExample {
pubic void myJavaMethod() {
}
public static void main(String[] args) {
System.out.println("Hello world!");
ScriptingContainer sc = new ScriptingContainer();
MethodsExample me = new MethodsExample();
Object rubyClass = sc.runScriptlet("Java::MethodsExample");
sc.put("MethodExample", rubyClass);
sc.runScriptlet("class MethodsExample ; def my_ruby_method ; puts 'YES!' ; end ; end");
// Expect true
sc.callMethod(me, "respond_to?" , new Object[]{"my_ruby_method"}, Boolean.class);
// Want false
sc.callMethod(me, "respond_to?" , new Object[]{"my_java_method"}, Boolean.class);
// Want false
sc.callMethod(me, "respond_to?" , new Object[]{"myJavaMethod"}, Boolean.class);
}
}
We want to call the Ruby method only if it is defined on the Ruby side, and ignore it if it is only defined on the Java side.
Any ideas on how to do this?
My first thought would be that the method is not getting defined on the class properly. Can you confirm that a call to the method from the Java side actually works? A la...
I know of no reason why reopening a Java class and adding methods would not appear on instances of that method. Obviously it works from Ruby: