Since now all objects that descend from Object (i.e. all objects in the system) gain that module's capabilities too. So ArrayList gains your module's add method. Then, when you call add on an ArrayList instance, we search through its class hierarchy looking for the method. Normally, this would fail with method_missing and we'd load add from the Java class. However, now that Object has included a module that defines its own add method, we find that instead.
Until there's a fix, you can work around it in a couple ways:
1. Don't define an add that gets included into the root object
2. Call add before including that add definition (which will cause it to be loaded for ArrayList and cached)
3. Don't use add to add to the ArrayList
- Charlie
On 3/15/06, David Corbin <[EMAIL PROTECTED]
> wrote:
On Wednesday 15 March 2006 08:58 am, Thomas E Enebo wrote:
> Ding! Any object that already exists in Ruby will get called
> before a method_missing. I am thinking about options. Yours is
> probably a pretty decent one...
I still don't understand. Can you respond to my earlier response?
>
> David, change your code to use << instead of add for right now to
> keep moving through any regressions...
I'll see if I can adapt. The original problem is not with ArrayList.
>
> -Tom
>
> On Tue, 14 Mar 2006, Charles O Nutter defenestrated me:
> > Ahh, here's my theory, based on a quick look.
> > It's because of the lazy loading of methods!!! Huzzah! I knew this one
> > would come around to bite us eventually.
> > Because we rely on method_missing to trigger Java methods to be
> > loaded, if Object has a method that we want to use in an included Java
> > class, we'll never reach it. We will search all the way to the top of
> > the JavaProxy's hierarchy and eventually find the real method before
> > we ever trigger method_missing.
> > SO. We need to fix it. The solution Tom and I kicked around was to
> > take the list of methods from the Java class and load some faux
> > methods into the list, so that "methods" returns an appropriate list
> > and so that we don't depend on method_missing tricks. When we do
> > actually call those methods, we'll prime them then.
> > Until then I'm not sure there's an easy fix...
> > - Charlie
> >
> > On 3/14/06, David Corbin <[1]dcorbin@machturtle.com > wrote:
> >
> > The arity for list.add is coming from ModA#add, without any real
> > reason to be.
> > I'm not sure if this is "special case for the 'default' object", or
> > not.
> > ---cut----
> > require 'java'
> > include_class ' java.util.ArrayList'
> > module ModA
> > def add a,b,c
> > end
> > end
> > include ModB
> > list = ArrayList.new
> > list.add "Foo"
> > ---end---
> >
> > --
> > Charles Oliver Nutter @ [2]headius.blogspot.com
> > JRuby Developer @ [3]jruby.sourceforge.net
> > Application Architect @ [4]www.ventera.com
> >
> > References
> >
> > 1. mailto:[EMAIL PROTECTED]
> > 2. http://headius.blogspot.com/
> > 3. http://jruby.sourceforge.net/
> > 4. http://www.ventera.com/
-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
Jruby-devel mailing list
Jruby-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jruby-devel
--
Charles Oliver Nutter @ headius.blogspot.com
JRuby Developer @ jruby.sourceforge.net
Application Architect @ www.ventera.com