From: Austin Ziegler Date: 2004-12-07T08:24:18+09:00 Subject: Re: Freezing Variable Assignment On Tue, 7 Dec 2004 07:12:37 +0900, itsme213 wrote: > "Eric Hodel" wrote >>> Correct. All instance variables of the object are frozen, not >>> the objects they refer to. >> No, the instance variables are not frozen, the instance 'a' of >> Effable is. >> >> #a= modifies a, which is disallowed because a is frozen. >> >> You cannot freeze variables, just objects. >> >> a = "foo" >> a.freeze >> a = "bar" > I respecfully but heartily disagree. Ruby freezes objects by > freezing their instance variables. The latter is the fundamental > operation. You may disagree, but you'd be incorrect. irb(main):008:0> class << a irb(main):009:1> def matz irb(main):010:2> "matz" irb(main):011:2> end irb(main):012:1> end TypeError: can't modify frozen object from (irb):9 (Assuming the same Effable that has been discussed to this point.) The object referred to by 'a' is frozen, not the instance variables of said object. The fundamental operation is *freezing the object*. > @a = "foo" > self.freeze > @a = "bar" > > Ruby just happens to treat local variables differently. There is > no fundamental reason to do so. Sure there is, and it's precisely because variables are simply labels, but instance variables are part of the state of the object. -austin -- Austin Ziegler * halostatue@gmail.com * Alternate: austin@halostatue.ca