Hi all, We're having a rather unique problem with class caching. We are implementing the strategy pattern in the following manner: 1. Set an accessor for the class, let's call it :strategy class Widget cattr_accessor :strategy end 2. In environment.rb, we instantiate an object that implements the strategy and use the accessor to set it for the class strat = MyStrategy.new Widget.strategy = strat 3. In the regular flow of the application, that strategy gets accessed so it can affect some behavior: ... Widget.strategy.do(:foo) ... OK, now in development mode, class caching is off. In Rails 0.14.3 this didn't seem to matter -- the class variable stayed set. But now mysteriously in Rails 1.0 I will get an exception when trying to call .do() on nil... ie, Widget.strategy becomes nil at some point. I'm assuming the class gets unloaded and then reloaded without :strategy ever getting set again. That's likely because the environment never got to set up the class variable again. So, in 0.14.3, did the environment get evaluated again? Or did the class never really get unloaded? Does anyone know a way I can avoid this problem? Is there a way to control class caching on a per-class basis? Looking at "module Dependencies" makes me believe there is not. Thanks for any help, rusty
on 2006-03-10 05:44
on 2006-03-10 05:59
> Does anyone know a way I can avoid this problem? Is there a way to > control class caching on a per-class basis? Looking at "module > Dependencies" makes me believe there is not. > > Thanks for any help, > rusty Try this on edge rails... class Widget < AR::Base def self.reloadable?() false; end end -- Rick O. http://techno-weenie.net
on 2006-03-10 05:59
> Try this on edge rails... > > class Widget < AR::Base > def self.reloadable?() false; end > end > Doh, sorry, I read that as 1.1.
on 2006-03-10 16:58
Rick O. wrote: >> Try this on edge rails... >> >> class Widget < AR::Base >> def self.reloadable?() false; end >> end >> > > Doh, sorry, I read that as 1.1. Hi Rick, Thanks for the reply! Are you saying that this problem can be addressed if I use Rails 1.1? Thanks, rusty