From: Thiago Arrais Date: 2006-04-04T02:13:51+09:00 Subject: Re: Dynamic code generation On 4/3/06, Michael Trier wrote: > Take with a grain of salt, because I don't really understand this > stuff. But, couldn't you do: > > irb(main):003:0> t = Time.at(0) > => Wed Dec 31 19:00:00 Eastern Standard Time 1969 > irb(main):004:0> t > => Wed Dec 31 19:00:00 Eastern Standard Time 1969 > irb(main):005:0> t.class > => Time > irb(main):006:0> t.class.now > => Mon Apr 03 12:53:14 Eastern Standard Time 2006 > irb(main):007:0> > > I'm calling the class level method of the instance variable. No, you are calling the class level method of the _class_ variable. The message `now` goes to the object returned by t.class (the Time class), not the object 't'. You would be calling the class level method of the instance variable if you did something like this irb(main):005:0> t = Time.now => Mon Apr 03 14:07:59 BRT 2006 irb(main):006:0> t.now NoMethodError: undefined method `now' for Mon Apr 03 14:07:59 BRT 2006:Time from (irb):6 from :0 Which, indeed, fails miserably. But if we think a little, this is actually a feature, not a bug. In order to call a method on the class object, we need to send a message directly to it. Messages to the instances are handled by them. Other languages actually allow this kind of auto-delegation. It would be interesting to know what people think about it. > Is that > what you're looking for? It was one of the solutions I came up with, but it didn't survive very long. See previous posts. Thanks, Thiago Arrais