In Ruby 1.9 you can have Fixnum
, Float
, and Symbol
values that are unfrozen or frozen:
irb(main):001:0> a = [ 17, 42.0, :foo ]; a.map(&:frozen?)
=> [false, false, false]
irb(main):002:0> a.each(&:freeze); a.map(&:frozen?)
=> [true, true, true]
I understand the utility of freezing strings, arrays, or other mutable data types. As far as I know, however, Fixnum
, Symbol
, and Float
instances are immutable from the start. Is there any reason to freeze them (or any reason that Ruby wouldn't report them as already frozen?
Note that in Ruby 2.0 Fixnum
s and Float
s both start off as frozen, while Symbol
s retain the behavior described above. So, it's slowly getting 'better' :)