From: "Guy N. Hurst" Date: 2001-04-28T02:43:18+09:00 Subject: [ruby-talk:14340] Re: Immutable Arrays? Johann Hibschman wrote: > > Hi folks, > > Is there any way to flag an Array as immutable, so I can use it > as a key in a hash table without worrying about it changing? This > is what the "tuple" in python is for, and there I find it useful. > > This comes up, since every now and then I want to simply use [x,y,z] > points as hash keys, and I would like to have some assurance that > this will not cause problems. > a = [2,3,4] # array a.freeze # now immutable a[1] = 0 # TypeError: can't modify frozen array hsh = { [1,2,3].freeze => "now immutable" } hsh[[1,2,3]] #=> "now immutable" Guy N. Hurst -- HurstLinks Web Development http://www.hurstlinks.com/ Norfolk, VA 23510 (757)623-9688 FAX 623-0433 PHP/MySQL - Ruby/Perl - HTML/Javascript