Project

General

Profile

Bug #5235

Ruby fails to freeze Strings and Numerics.

Added by katmagic (Kat Magic) about 9 years ago. Updated about 9 years ago.

Status:
Rejected
Priority:
Normal
Assignee:
-
Target version:
ruby -v:
ruby 1.9.2p0 (2010-08-18 revision 29036) [i686-linux]
Backport:
[ruby-core:39127]

Description

x = 0
x.freeze()
x += 1
x # => 1

s = ""
s.freeze()
s += "a"
s # => "a"

Updated by aprescott (Adam Prescott) about 9 years ago

This is not a bug. x += 1 is sugar for x = x + 1, and x + 1 does not
modify the receiver. Similar for s += "a".

s = ""
s.freeze
s.replace("nothing") #=> RuntimeError: can't modify frozen string

Updated by matz (Yukihiro Matsumoto) about 9 years ago

  • Status changed from Open to Rejected

#freeze prohibits modification to an object, not a variable.

Also available in: Atom PDF