Is there a nicer way to call Ruby method from Java?

I have in my Java class a variable of type IRubyObject, which actually
points to a RubyObject:

// Java
RubyObject ro = get_it_from_somewhere();
IRubyObject iro = ro;

The RubyObject holds an object of some Ruby class, and this class in
turn has a method expecting one parameter (which is supposed to be a

# Ruby
def myfunc(msg)

I want to invoke this method from Java, and I’m not interested in the
return value. This is my code:

  // Java
  Ruby runtime = iro.getRuntime();
  ThreadContext currentContext = runtime.getCurrentContext();
  iro.callMethod(currentContext, "myfunc",

JavaEmbedUtils.javaToRuby(runtime, “string passed to myfunc”));

My question: Is it possible to code this a bit simpler?

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs