[#70843] Re: [ruby-cvs:58952] hsbt:r51801 (trunk): * lib/rubygems: Update to RubyGems HEAD(fe61e4c112). — Eric Wong <normalperson@...>
hsbt@ruby-lang.org wrote:
3 messages
2015/09/17
[ruby-core:70863] [Ruby trunk - Feature #11473] Immutable String literal in Ruby 3
From:
andrew@...
Date:
2015-09-19 06:40:44 UTC
List:
ruby-core #70863
Issue #11473 has been updated by Andrew Vit. Rodrigo Rosenfeld Rosas wrote: > Hi Andrew, why mutating a string would change every other place the string is referenced? Wouldn't the string reference remain the same? ~~~ a = "asdf".freeze b = "asdf".freeze a.object_id == b.object_id ~~~ Frozen strings for the same value are the same object. If you "unfreeze" one, it would change every other one. Two copies of a string can have the same value for different reasons; it would be very wrong if both changed. On the other hand, if we automatically dup it then it's just like doing this, which won't do what you expect: ~~~ builder = "".freeze (builder.dup) << "asdf" builder == "asdf" # false ~~~ ---------------------------------------- Feature #11473: Immutable String literal in Ruby 3 https://bugs.ruby-lang.org/issues/11473#change-54245 * Author: Koichi Sasada * Status: Open * Priority: Normal * Assignee: Yukihiro Matsumoto ---------------------------------------- Matz said "All String literals are immutable (frozen) on Ruby 3". This ticket is place holder to discuss about that. -- https://bugs.ruby-lang.org/