From: Stefano Crocco Date: 2010-10-15T00:22:49+09:00 Subject: Re: Freeze method doesn't work On Thursday 14 October 2010, Sergey U. wrote: > |Freeze should prevent further modifications to 'var'... No. freeze prevents modifications to the object contained in var. For example: str = "hello" str.upcase! puts str => HELLO str.freeze str.downcase! => RuntimeError: can't modify frozen string str1 = str str1.downcase! => RuntimeError: can't modify frozen string Note that freeze is useless on classes (like Integer or Symbol) which don't have destructive methods. The nearest you can come to prevent modifications to a variable is to use a constant instead (but remember that ruby allows you to assign a different value to a constant, it just emits a warning). However, the object the constant contains can be freely modified: CONST="hello" CONST.upcase! puts CONST "HELLO" CONST="bye" => warning: already initialized constant CONST puts CONST => "bye" If you also want to prevent modifications to the object in the constant, freeze it. I hope this helps Stefano