On Oct 20, 2010, at 1:29 PM, John W Higgins wrote: > Morning Chuck. > > On Wed, Oct 20, 2010 at 8:31 AM, Chuck Remes <cremes.devlist / mac.com> wrote: > >> I have a class that I would like to "freeze" when it reaches a particular >> state so that it becomes read-only. I do *not* want to use the existing >> #freeze method because it raises an exception when there is an attempted >> mutation on a frozen object and I want the attempt to be silent. It appears >> that the best way to enforce this (state machine pattern) is by redefining >> the accessors and other methods that cause mutations to be no ops. >> >> What is the preferred practice for doing that? >> >> > You could in the alternative have the ops that mutate do an "unless" at the > top of the method to bake the freeze into the method as opposed to > redefining Thanks for everyone for their suggestions. Instead of using metaprogramming, which in this case is apparently quite problematic, I'll go with the easiest solution of doing an "unless" check in certain key methods. Obviously that won't prevent a future developer from adding singleton methods to the object(s) or messing with them in some other way, but that will clearly break the contract. The docs will say "don't do this" and leave it at that. Thanks again. cr