From: HarryO Date: 2001-07-10T12:31:56+09:00 Subject: [ruby-talk:17588] Re: Constants and Variables In article <8lt27.86943$2u2.2069294@e420r-sjo2.usenetserver.com>, "Dave Thomas" wrote: > "HarryO" writes: > >> > If you want objects that don't change, try Object#freeze, >> > Object#frozen?. >> >> Here's a thought ... why not just say that freeze is the only way >> things are made immutable? Then, could we not have code like ... >> >> MAX_SIZE = 100.freeze >> >> to define that MAX_SIZE is a constant? > > Because that freezes the object that MAX_SIZE references, not MAX_SIZE > itself. Of course! Sorry, I should have realised that. However ... I figured I could then do max_size = 10 max_size.freeze max_size = 5 # 3 puts "max = #{max}" # 4 and line 3 would produce an error, line 4 would print 10. However, that doesn't work. I get no errors and max_size prints as 5. Am I just really thick, or is there a bug here? By the way, I'm running 1.7.1 as built July 3rd.