Forum: JRuby Tuning the Java to Ruby method name translator

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
E5b03a942a97535bf3c69ca68f203dd1?d=identicon&s=25 John W. (john_w54)
on 2013-10-08 15:26
Is there any way to tune the translator that turns Java-formatted method
names into Ruby-formatted method names? I'm using JAXB-generated classes
for an XML schema to create Ruby bindings and am encountering cases
where the translation is very unintuitive.

For example, "getIndicatedTTPs" is getting turned into
"get_indicated_tt_ps" when I would prefer something like

Obviously I can solve this as a one-off by aliasing the method but "TTP"
is a common term throughout the schema (and therefore the generated
content) so I'd rather just tell it to turn "TTPs" into "ttps" as a
global case.

I briefly looked through the JRuby code and Googled but wasn't able to
find any easy way to hook into it to do this.

Charles Monteiro (Guest)
on 2013-10-09 20:40
(Received via mailing list)
but you can also call it with the original method name, right ? I'm
missing something , what translator do you mean ? I figured jruby did
the match at invocation time , does Jruby actually insert new method
keys in the method dictionary on the Java proxy class to accommodate for
the snake style method naming convention ? Just curious

E5b03a942a97535bf3c69ca68f203dd1?d=identicon&s=25 John W. (john_w54)
on 2013-10-09 21:00
Yes, you can still call it with the original method name (as well as the
poorly translated name). So it's not "broken" per se, but I'm developing
a library for others to use and would like to give them a clean and
consistent Ruby-style interface.

I can't profess to know much about the internals of JRuby but if you
inspect an instance of a Java proxy class it has both the original
Java-style methods and the translated Ruby-style methods defined.
486ca04f06d968004643ce5b47376ded?d=identicon&s=25 Keith B. (keith_b)
on 2013-10-10 05:43
(Received via mailing list)
Charles -

I posted a pry session at
that shows a Java class (java.util.Locale).  Note the default=, which is
a Rubified version of setDefault.  It's interesting that setDefault is
not listed there, although it works, as shown in the pry session.
Anyway, to answer your question, it's not done at invocation time.

- Keith
Christian MICHON (Guest)
on 2013-10-10 07:50
(Received via mailing list)
"It's interesting that setDefault is not listed there, although it
as shown in the pry session"

Well, this seems to be a side effect of pry only (like pry applying some
smart filter in case of java setters/getters?)...

If you try this (in a similar session pry session, but _not_ using pry
'ls'), you'll see it should be listed:

[10] pry(Java::JavaUtil::Locale):1> methods.grep /default/i
=> ["set_default",
Charles Monteiro (Guest)
on 2013-10-10 17:51
(Received via mailing list)

So I guess when one utilizes an external jar , Jruby must at least
lazily cache the selectors.

This topic is locked and can not be replied to.