Robert Dober
7/2/2007 9:09:00 AM
<snip>
> irb(main):016:1> end
> => FooBar
> irb(main):017:0> a.bar
> NoMethodError: undefined method `bar' for #<Baz:0x330568>
> from (irb):18
>
> We need a guru to explain why...
That is definitely not me, but there was a very interesting thread by
Tom (aka Trans) very recently and Pit provided a nice metaprogramming
tool to address the issue which is called "double inclusion". [ Sorry
I am bad at finding references to threads :( ]
As a matter of fact there is an easy way to update the method lookup chain
just continue as follows in your irb session:
irb(main):019:0> class Baz
irb(main):020:1> include FooBar # Play it again Sam
irb(main):021:1> end
=> Baz
irb(main):022:0> a.bar
=> :bar
It has something to do with the proxies that are created for included
modules, maybe a Guru will explain this in detail.
Cheers
Robert
>
> Alex Gutteridge
>
> Bioinformatics Center
> Kyoto University
>
>
>
>
--
I always knew that one day Smalltalk would replace Java.
I just didn't know it would be called Ruby
-- Kent Beck