From: Phlip Date: 2009-02-06T12:19:27+09:00 Subject: Re: Method Precedence Daly wrote: > Hello all, > > If I have a class such as: > > class Example > > def one > puts "one" > > def two > puts "two inside one" > end > end > > def two > puts "two inside Example" > end > > end > > And I do: > e = Example.new > e.one > e.two > > I get, obviously: > one > two inside one > > What I don't understand is that if after that I do: > f = Example.new > f.two > > I still get: > two inside one When the compiler first encountered Example, it plugged one() and the outer two() into Example's class instance list. The first call to one() then bonds the inner two() to the class. The object did not get affected in either case. (Always remember classes are objects around here!) If you ran the program again (a new Ruby "VM"), and never called one(), you would only get the outer two(). -- Phlip