From: Dave Aronson Date: 2011-11-11T06:06:34+09:00 Subject: Re: How Am I to Understand This Class Behavior? On Thu, Nov 10, 2011 at 15:39, Nik Z. wrote: >   The following code gets me wondering: how come the last "puts" gets > printed without initializing on the Foo class at all... ... > class Foo >    def initialize >    end > >    puts "How does this get printed without Foo.new???" > end When you define a class, all the stuff at the top level of the definition is executed. Methods and variables get defined and attached to the class, and other stuff just gets executed. That includes this puts call. If you only wanted it executed when Foo.new gets called, it needs to be inside initialize. -Dave -- LOOKING FOR WORK! What: Ruby (on/off Rails), Python, other modern languages. Where: Northern Virginia, Washington DC (near Orange Line), and remote work. See: davearonson.com (main) * codosaur.us (code) * dare2xl.com (excellence). Specialization is for insects. (Heinlein) - Have Pun, Will Babble! (Aronson)