Passing parameters to jruby

I’ve been having a lot of fun with jruby in my java app, but so far
I’ve just been calling jruby, which kind of manages my my java app
like it’s a library. It’s given me pretty fast feedback for minor
tweaks. Now, however, I’d like to send parameters to ruby functions.
I’ve seen examples using put() to set the java object in the
ScriptEngine and then reference that function, but I was just curious
if there was a way to call it directly.

In java

engine.eval(“foo()”, arg1, arg2)

and in jruby

def foo(arg1, arg2)

end

Hi,

On Wed, Dec 29, 2010 at 1:40 PM, Josh S.
[email protected] wrote:

engine.eval(“foo()”, arg1, arg2)

and in jruby

def foo(arg1, arg2)

end

Adding new method isn’t possible unless we change JSR223 spec.
But, in this case, JSR223’s Invocable.invokeFunction()/invokeMethod
seems to work. For example,

Object receiver = engine.eval();
((Invocable)engine).invokeMethod(receiver, arg1, arg2)

Hope this helps,
-Yoko