On Mon, Sep 21, 2009 at 9:53 PM, Logan Barnett <logus...@gmail.com> wrote:
> How does everyone feel about leveraging some more duck-typing in Ruby? Maybe
> this was mentioned already, but I'll just repeat it if that's the case:
>
> I often have code that could be simplified to something like this:
> yell_text_field.text = yell_text_field.text.upcase
>
> I really don't care that it's a String, just that it behaves like a String
> (:

In the current case, of course, yell_text_field.text auto-coerces back
to a Ruby String, which can then upcase and be re-coerced back to a
Java string for the assignment. The trouble there is that instead of
one new string being constructed (for .upcase) we actually construct
three (the other two being the coerced products).

In the proposed newer case, the .text call should just return a Java
String, which could certainly support all of Ruby String's
non-mutating operation. The result in this case would be that we only
create one new String, for .upcase, and pass everything else straight
through.

> I'm not sure if that's a lot of work or not, but if that can be achieved
> then it really doesn't matter what's being passed around. Maybe these
> objects would also respond to kind_of? in a cheating manner (Java's String
> returns true when asked if kind_of? a Ruby String), but I'm not convinced
> that's a super great idea.

Yes, I'm not convinced it's a good idea either. The main problem I see
is that the Java String needs to reflect its own object hierarchy; it
needs to be < Java Object and CharSequence and so on. By trying to
force it to be kind_of? String we break its relationship with other
Java types.

- Charlie

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

    http://xircles.codehaus.org/manage_email


Reply via email to