From: "Peter V." Date: 2010-12-18T05:12:56+09:00 Subject: Re: Integer/Fixnum/Bignum are "immutable"? Kedar Mhaswade wrote in post #969114: >> If your definition of the "value" of an Integer is its numeric value, >> you don't have any way to change. Note that in Ruby even a fixnum can >> have >> its own instance variables. > > Got it. That clarifies. Thanks! > > A related question is if the above were true, shouldn't 2.frozen? have > returned true (or else I don't understand what 2.frozen? means)? For Fixnum, I believe there are simply no setter methods for the "numeric value" so the "frozen" state is not required to make the "numeric value" immutable. But 'freeze' and 'frozen?' do work on an FixNum object. $ irb #ruby-1.9.2-head > speed = 150 #=> 150 > speed.object_id #=> 301 > speed.frozen? #=> false > speed.instance_variable_set '@accuracy', '+/- 2' #=> '+/- 2' > speed.freeze #=> 150 > speed.frozen? #=> true > speed.instance_variable_set '@accuracy', '+/- 1' RuntimeError: can't modify frozen object from (irb):8:in `instance_variable_set' from (irb):8 from /home/peterv/.rvm/rubies/ruby-1.9.2-head/bin/irb:16:in `
' > speed = 160 #=> 160 # does not change internal state, > speed.object_id #=> 321 # but now refers a different object HTH, Peter -- Posted via http://www.ruby-forum.com/.