From: "David A. Black" Date: 2010-08-12T09:29:03+09:00 Subject: Re: Can't change the value of self - II On Thu, 12 Aug 2010, Ralph Shnelvar wrote: > Wednesday, August 11, 2010, 5:52:57 PM, you wrote: > > jR> You can use the #replace method to do that sort of thing: > > jR> self.replace "Help! Oh, well, I'm saved!" > > jR> This method is defined in classes String, Hash, Array, and Set, and > jR> works the same way in each one. > > jR> jeremy > > > jeremy, > > That's great and solves my particular problem. > > But what if the class being derived from does not have a replace method? If the object has state that can be modified, then there will be (by definition) ways to modify that state. If it doesn't, then there won't be, and the class in question is probably a bad starting point if you want to create objects with state that can be modified. That's one of the advantages of using proxy objects and delegators: you gain an extra axis along which you can make decisions about things like object state. Even though you can't change (say) a Fixnum, you can create objects with integer attributes that *can* be changed. David -- David A. Black, Senior Developer, Cyrus Innovation Inc. The Ruby training with Black/Brown/McAnally Compleat Philadelphia, PA, October 1-2, 2010 Rubyist http://www.compleatrubyist.com