From: Matthew Desmarais Date: 2006-04-12T06:56:26+09:00 Subject: Re: Equivalent of Java static code block in Ruby? Simon Kræ—¦ger wrote: > Wes Gamble wrote: > >> That's fine but I only want it executed ONCE the first time the class is >> loaded. >> >> I have a Rails application that creates a new INSTANCE of a controller >> class every time a certain URL is requested. >> >> All of the code that isn't in methods is being executed every time the >> instance is created. >> > > > Maybe i don't understand but i think this is plain wrong: > > class A > puts "Hello" > end > > 100.times do > a = A.new > end > > #=> Hello > > cheers > > Simon > I think you need to find out why the class is being loaded multiple times. I may be completely off base here, but don't you load your entire app every time that you get a new request in Rails development mode? That would explain the results that you're seeing. Regards, Matthew Desmarais