Created
September 26, 2008 19:10
-
-
Save vic/13179 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
class Bar | |
end |
This file contains hidden or 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
puts "QUE CHIDOOO" | |
class Foo | |
end |
This file contains hidden or 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
import org.jruby.*; | |
/* | |
The use case I have: | |
- Create a JRuby runtime | |
- Load a gem on it .. actually that gem ("buildr") requires many other gems and takes a lot of time to get them loaded (about 2secs) | |
- Use that preloaded runtime to create clones | |
- Load a buildfile on that clone, without affecting the original runtime | |
- drop the used cloned runtime, | |
- Use the preloaded runtiem to create another clone next time we run. | |
*/ | |
public class Main { | |
public static void main(String[] args) { | |
Ruby one = Ruby.newInstance(); | |
one.getLoadService().require("foo"); | |
System.out.println("one.FOO = "+one.getObject().const_defined_p(one.getCurrentContext(), one.newSymbol("Foo"))); | |
Ruby two =(Ruby) one.clone(); | |
two.getLoadService().require("bar"); | |
System.out.println("two.FOO = "+two.getObject().const_defined_p(two.getCurrentContext(), two.newSymbol("Foo"))); | |
System.out.println("one.BAR = "+one.getObject().const_defined_p(one.getCurrentContext(), one.newSymbol("Bar"))); | |
} | |
} |
This file contains hidden or 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
require 'jruby' | |
one = org.jruby.Ruby.newInstance | |
one.load_service.require 'foo' | |
p one.getObject.const_defined?(:Foo) | |
p one.java_object.dup | |
two = one | |
p two.getObject.const_defined?(:Foo) | |
one.load_service.require 'bar' | |
p one.getObject.const_defined?(:Bar) | |
p two.getObject.const_defined?(:Bar) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment