From: Austin Ziegler Date: 2003-08-05T10:42:30+09:00 Subject: Re: clearing a parameter in Ruby? On Tue, 5 Aug 2003 04:56:50 +0900, Roy Patrick Tan wrote: > Austin Ziegler wrote: >> Why do you wish to do this? We might be able to help you figure out a >> better way to do what you're trying to do. > In essence, what I'm trying to do is create a set of container classes > that, when an object is inserted into a container, the container > guarantees that the object does not change state until it is taken out > again. class ImmutablesArray < Array def push(it) it.freeze super end end Roughly. There's a few other methods you would want to implement (like #pop) to unfreeze as you pop the item, but this should work in general. > The problem is that in Ruby (and almost all modern imperative languages) > two variables can refer to the same object. So can C++. If you want objects in Ruby immutable, #freeze them. > I guess your real question is, what kind of software am I building that > requires these kind of components? I don't really need them, I was > writing what was supposed to be a quick and dirty program when I realized > how totally reliant I am on aliasing, and wondered how easy it would be > to implement in Ruby some of the non-aliasing components I've been > studying. I'm not sure what you mean by "aliasing" here. -austin -- austin ziegler * austin@halostatue.ca * Toronto, ON, Canada software designer * pragmatic programmer * 2003.08.04 * 21.38.17