Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.Sign up
proc-to-interface conversion clones String based objects #5603
Proc-to-interface conversion should preserve the object returned by the ruby block
If the ruby block returns a String or any subclass of String the interface proxy returns a copy of the underlying object as String loosing the actual type. The behavior is correct for any other type.
Then the following ruby script
produces the following output:
believe this is "normal" for bare String -> since JRuby always converts Ruby -> Java by default.
yeah, its definitely that - and Integers also get a round-trip going
there isn't any fix for a patch release as it would like break existing scripts using Java Integration.
@kares found another type that is being converted to Java:
@klobuczek Going through Java integration there's currently no way to prevent the coercion to a Java type and back to Ruby; on the Java side, if you're calling an API that wants a string, we have to pass it a string.
We have considered adding more knobs and features to Java integration to allow you to control that coercion directly, but there has never been any consensus on what that ought to look like.
An alternative way to do what you want is to implement a small part of your library as a JRuby extension (in Java or another JVM language) and use that to interact with the rest of the JVM world. That will allow you to pass the IRubyObject directly through to the JRuby ext, and from there you can do what you wish.
You say that using IRubyObject did not work for you...do you have an example of what you tried?