From: Andrey Kulinich Date: 2003-07-03T17:33:00+09:00 Subject: Re: Auto-serialization (as in Vapor, sql-serialize, etc.): detecting changes to instance variables Anders Borch wrote: > I think you should not allow anyone to modify your instance variables > without going through your accessor methods. It ruins everything that > encapsulation gives you. Sometimes you can't control modification. class Session attr_accessor :modified def initialize @data = {} @modified = false end def []( key ) @data[key] end def []=( key, value ) @data[key] = value @modified = true end end session = Session.new session[:arr] = [] session.modified # true. all ok session.modified = false session[:arr].push( 1 ) session.modified # false :( > Using the method_missing to test if the object has changed after each > method call *could* solve your problem. There is a trouble with method_missing: you can't redirect methods 'to_s', '==' and other Object's methods, because they are defined in Wrapper. -- with best regards, Andrey Kulinich IT Group Software developer phone/fax +380 (372) 58-43-10 e-mail: Andrey.Kulinich@itgrp.net http://www.itgrp.net