Jruby embedded modules and classes.

Posted by James Moore on Stack Overflow See other posts from Stack Overflow or by James Moore
Published on 2010-03-30T20:24:56Z Indexed on 2010/03/30 20:43 UTC
Read the original article Hit count: 487

Filed under:
|
|

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

© Stack Overflow or respective owner

Related posts about jruby

Related posts about ruby