Created
February 3, 2011 21:54
-
-
Save cowboyd/810291 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
java_class: class org.jruby.proxy.spike.Spike$Proxy0 | |
java_class: class org.jruby.proxy.spike.Spike$Proxy0 | |
Foo.java_class: spike.Spike | |
Foo.java_class.respond_to?(:isAssignableFrom): false | |
java_class.respond_to?(:<=): false | |
java_class.respond_to?(:isAssignableFrom): true | |
java_class == Foo.java_class: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package spike; | |
import org.jruby.embed.ScriptingContainer; | |
public class Spike { | |
public void inspectClass(Class cls) { | |
System.out.println("java_class: " + cls); | |
} | |
public void doInspection(Spike inspected) { | |
inspectClass(inspected.getClass()); | |
inspected.inspectClass(inspected.getClass()); | |
} | |
public static void main(String[] args) { | |
ScriptingContainer ruby = new ScriptingContainer(); | |
ruby.getVarMap().put("spike", new Spike()); | |
ruby.runScriptlet(Spike.class.getResourceAsStream("spike.rb"), "spike.rb"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Given a java class that could be a proxy class instance, how can you | |
# a) find the actual ruby class that it is a proxy for so that | |
# b) you can compare it to see if it contains another ruby class/module | |
# in it's list of ancestors | |
# basically what I'd like to do is evaluate | |
# java_class <= Foo | |
# or | |
# java_class <= Java::Spike::Spike | |
# | |
# but I just can't seem to find a way to compare them :-/ | |
class Foo < Java::Spike::Spike | |
def inspectClass(java_class) | |
puts "java_class: #{java_class}" | |
puts "Foo.java_class: #{Foo.java_class}" | |
puts "Foo.java_class.respond_to?(:isAssignableFrom): #{Foo.java_class.respond_to?(:isAssignableFrom)}" | |
puts "java_class.respond_to?(:<=): #{java_class.respond_to?(:<=)}" | |
puts "java_class.respond_to?(:isAssignableFrom): #{java_class.respond_to?(:isAssignableFrom)}" | |
puts "java_class == Foo.java_class: #{java_class == Foo.java_class}" | |
end | |
end | |
foo = Foo.new | |
spike.doInspection(foo) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment