On Wed, Sep 23, 2009 at 10:44 AM, Yoko Harada <yoko...@gmail.com> wrote:
> Let me clarify. There are two types of variables when users use JRuby:
> Java originated variables used in Ruby, and Ruby originated variables
> used in Java. The new coerce_to? method is for the latter one, Ruby
> originated variables used in Java, right? Currently, JRuby Embed uses
> JavaEmbedUtils#rubyToJava method to convert types of all variables
> used in Ruby so that Java program can use those in it. Will the
> coerce_to? affect rubyToJava method?

Well sort of. This is for calling Java methods from Ruby and figuring
out based on the target object's class and the incoming arguments
which method to call and how to get the arguments converted to those
target argument types.

> I think this change is influential to older codes. If users specify
> Ruby types when giving variables from Java to Ruby, will it covers the
> change? For example, by new method, "javaToRuby(Ruby runtime, Object
> value, Class rubyType)" whereas we have  "javaToRuby(Ruby runtime,
> Object value)" only right now.

This is still all on the Ruby side...but the implication would be that
when you do something like

str = java.lang.System.get_property('foo')

The 'foo' would coerce to a Java string on the way in, but the return
value would not auto-coerce back to a Ruby String. It would ideally
look and feel like a Ruby String and have all the expected
non-mutative methods working fine, and you could call to_s or to_str
to actually force it to become a Ruby String. The intention here is
that whereever possible we could just leave objects as-is and not pay
the coercion cost until the user actually wants to pay it, rather than
forcing strings to coerce on every call.

> This is nice feature. Then, how about interface implementation by
> Ruby? Like in the below?
>
> // Java
> public interface Overloads {
>  public void go(int i);
>  public void go(long i);
> }
>
> // Ruby
> class Overloads
>  include Java::Overloads
>  def go(i, [Java::int])
>    # implementation for int
>  end
>  def go(i, [Java::long])
>    #i implementation for long
>  end
> end
> Overloads.new
>
> If this is possible, it would be useful when we implement interfaces
> defined in some specification.

This is definitely going to be supported in some version of the JRuby
compiler, both for runtime-created classes and for ahead-of-time
compiled code. It will probably look something like this, but it's
still work in process. You could look at ruby2java gem for now to see
one possible way of specifying interface impl and signatures.

- Charlie

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply via email to