From: Jim Freeze Date: 2002-11-21T22:59:52+09:00 Subject: Re: [FAQ] Interpreted vs compiled [FAQ] defining methods anywhere On Thursday, 21 November 2002 at 14:42:35 +0900, Dave Thomas wrote: > Mark Wilson writes: > > > Please explain how methods in an explicit class are different than > > methods in the Object class. > > They aren't - it's just a question of when they are called: > > bert > def bert > ... > end > > Here, the call to bert is *executed* before the definition of bert: it > fails. > > class Dave > def initialize > bert > end > def bert > ... > end > end > > Here the call to 'bert' in initialize is parsed, but not executed. The > method 'bert' is then defined. So, that would explain the example below: class Fred Fred.fred # this fails def self.fred puts "1" end Fred.fred # this works end I guess I am now coming to the realization that when I define a method at the top level, that somehow it is automatically instantiated. ...There has to be some type of parser difference, or the following would work: class Fred def fred puts "1" end fred # undefined local variable or method `fred' for Fred:Class end Can someone please explain? Thanks -- Jim Freeze ---------- Paul's Law: You can't fall off the floor.