From: Joel VanderWerf Date: 2007-09-07T04:34:05+09:00 Subject: Re: Symbols and frozen strings Brian Candler wrote: >> Setting aside the question of freezing, why can't ruby share string data >> for all strings generated from the same symbol? > > Because it could generate unexpected aliasing. The normal, expected > behaviour is no aliasing: > > irb(main):001:0> a = :foo.to_s > => "foo" > irb(main):002:0> b = :foo.to_s > => "foo" > irb(main):003:0> b << "bar" > => "foobar" > irb(main):004:0> a > => "foo" This was what I was thinking of: irb(main):001:0> a = :foo.to_s => "foo" irb(main):002:0> b = a.dup => "foo" irb(main):003:0> b << "bar" => "foobar" irb(main):004:0> a => "foo" Internally, a and b use the same storage, but copy-on-write prevents aliasing. -- vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407