Skip to content

Instantly share code, notes, and snippets.

@vic
Created Sep 26, 2008
Embed
What would you like to do?
class Bar
end
puts "QUE CHIDOOO"
class Foo
end
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")));
}
}
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