Jruby embedded modules and classes.
- by James Moore
Hey,
I have a ruby file as follows:
module Example
class Myclass
def t_st
"Hello World!"
end
end
end
now if this was just a class I would be able to use the following java code:
ScriptEngine jruby = new ScriptEngineManager().getEngineByName("jruby");
jruby.eval(new BufferedReader(new FileReader("example.rb")));
Object example = jruby.eval("myclass.new");
However, this class rests inside a module. Calling the same code as above produces the error:
Exception in thread "main" org.jruby.embed.EvalFailedException: uninitialized constant myclass
In addition, calling:
Object example = jruby.eval("Example");
The module returns no error. So one would assume this follows the format for Ruby.
Object example = jruby.eval("Example::myclass.new");
Again however, I get the same error as before.
Can anyone help? As there is little documentation on JRuby?
Thanks