From: Dennis Decker Jensen Date: 2001-04-29T02:48:33+09:00 Subject: [ruby-talk:14382] Re: Immutable Arrays? Johann Hibschman wrote: | Guy N. Hurst wrote: | | > a = [2,3,4] # array | > a.freeze # now immutable | > a[1] = 0 # TypeError: can't modify frozen array | | Thanks. Would there be anything obviously wrong with: | | class Tuple < Array | def initialize (values) | replace values | freeze | end | end | | as a "freezer" object? Or is this just getting silly? | Notice the default behaviour for String-keys (Thanks to Dave and Andy for RI): --------------------------------------------------------------- Hash#[]= hsh[ aKeyObject ] = aValueObject -> aValueObject ------------------------------------------------------------------------ Element Assignment---Associates the value given by aValueObject with the key given by aKeyObject. aKeyObject should not have its value changed while it is in use as a key (a String passed as a key will be duplicated and frozen). h = { "a" => 100, "b" => 200 } h["a"] = 9 h["c"] = 4 h #=> {"a"=>9, "b"=>200, "c"=>4} I think it would be better if Hash#[aKeyObject] always duplicated and froze aKeyObject no matter what the type of aKeyObject should be. That way you wouldn't have to worry of side-effects. Should this become a RCR? Regards, Dennis Decker Jensen