From: Chris Shea Date: 2008-04-23T11:55:04+09:00 Subject: Re: Extending Hast class with custom [] []= methods On Apr 22, 7:31 pm, Chris Shea wrote: > On Apr 22, 6:15 pm, Daniel Finnie wrote: > > > Hi, > > > You can use super and/or alias: > > > class MyHash < Hash > > def [] key > > super(key.downcase) > > end > > end > > But he asking for case-insensitivity. If a key is created with > uppercase letters, you're out of luck. And if you look for a value > for a non-string key, that's no good either: > > ### > class MyHash < Hash > def [](key) > super(key.downcase) > end > end > > h = MyHash.new > h['A'] = 'never findable' > h['A'] # => nil > h[1] # ~> undefined method `downcase' for 1:Fixnum (NoMethodError) > ### > > You could override []= as well (and with more care), but I wonder if a > different class with a Hash instance variable with mediated access > would be a better route. > > Chris Or just use Rubinius: http://pastie.textmate.org/185232 !!! Chris