From: Julian Leviston Date: 2009-02-06T23:40:33+09:00 Subject: Re: Using a Class (not an instance) into threads LOL yeah I know this, but what did faster mean in that context? More efficient? Less work? Something else? Blog: http://random8.zenunit.com/ Learn rails: http://sensei.zenunit.com/ On 07/02/2009, at 12:27 AM, Iñaki Baz Castillo wrote: > 2009/2/6 Julian Leviston : >> What do you mean by faster? For who? > > ------------------------ > class MyClass > > class << self > puts "Starting MyClass..." > @my_var = 1 > end > > class << self > def hello > puts "hello I'm MyClass" > end > end > > end > > > class MyClass2 > > def initialize > puts "Initializing instance of MyClass2..." > @my_var = 1 > end > > def hello > puts "hello I'm instance of MyClass2" > end > > end > > MyClass.hello > MyClass.hello > > MyClass2.new.hello > MyClass2.new.hello > ------------------------ > > > output: > > -------------------- > Starting MyClass... > hello I'm MyClass > hello I'm MyClass > Initializing instance of MyClass2... > hello I'm instance of MyClass2 > Initializing instance of MyClass2... > hello I'm instance of MyClass2 > -------------------- > > > > As you see, the MyClass code: > puts "Starting MyClass..." > @my_var = 1 > is executed *just* at the start of the program, while the code: > puts "Initializing instance of MyClass2..." > @my_var = 1 > is executed for each MyClass2 initialization (logic of course). > > > Regards. > > -- > Iñaki Baz Castillo > >