From: Paul Smith Date: 2007-01-11T13:36:08+09:00 Subject: Re: statement outside of any method in a class Thanks for the explanation David. However, it is still not clear to me when these statements are invoked. In your example, what triggers the execution of the 2 statements? > class C < SomeClass > puts "self right now is #{self}." # self right now is C. > do_something # Hi! > end When the class is loaded, when an instance of that class is created? Is this similar to a static initialization block in Java? P. >> Could someone explain what the invocation model is >> for that statement that is not bound to any method >> within a class (i.e. when is that statement executed?) > > It's the same, in the abstract, as the invocation model generally: a > "bareword"-style method is automatically invoked on the current > default object, self. At the outer level of a class definition, self > is the class object itself. So what you're seeing is a call to a > class method. > > Here's a little X-ray of what's going on: > > class SomeClass > def self.do_something > puts "Hi!" > end > end > > class C < SomeClass > puts "self right now is #{self}." # self right now is C. > do_something # Hi! > end > > There are more nuances but that's the basic scenario. > > > David -- Posted via http://www.ruby-forum.com/.