From: Paul Brannan Date: 2002-02-25T23:29:14+09:00 Subject: Re: dispatching and class references On Sat, Feb 23, 2002 at 03:41:03PM +0900, Michal Rokos wrote: > Paul: Do you think that there is no need for method like > "deep_freeze"? (I don't care about name - you know what it > should do.) I think there is some use for such a method, but I'm not sure how it should work. Consider: class Bar def initialize(s) @s = s end def foo @s[0] = ?b end end s = 'foo' b = Bar.new(s) b.freeze b.foo p s #=> "boo" Should the call to foo raise an exception? If so, then should: s = 'foo' b = Bar.new(s) b.freeze s[0] = ?b p s #=> "boo" also raise an exception? Similarly, what about: class Foo def initialize(b) @b = b end def foo eval("x = 42", @b) end end x = 0 f = Foo.new(binding) f.freeze f.foo p x #=> 42 vs.: x = 0 f = Foo.new(binding) f.freeze x = 42 p x #=> 42 Paul