Could anyone say me, how should I use an existing Java object in a JRuby script?
I know how I can create a new instance of a Java class in JRuby, but in my case I have already an instance in Java and I want to check/modify some properties of it in my JRuby script.
//Java
public class MyClass
{
private int size;
public int getSize() {
return size;
}
public void setSize(int size) {
this.size = size;
}
}
//...
MyClass myClass = new MyClass();
myClass.setSize(5);
//...
String script = "..????.."
ScriptingContainer rubyContainer = new ScriptingContainer();
rubyContainer.runScriptlet(script);
What should I write into the script variable to check and modify the size property like this:
if (myClass.getSize() > 3)
myClass.setSize(10)
else
myClass.setSize(0);
After the modification I'd like to be able to use the new value of the property in my Java code.
Thanks a lot!