From: Robert Klemme Date: 2008-04-23T16:23:35+09:00 Subject: Re: Extending Hast class with custom [] []= methods 2008/4/23, Robert Klemme : > 2008/4/23, Chris Shea : > > > Or just use Rubinius: http://pastie.textmate.org/185232 > > > Or delegation Copy and paste error: this was missing: require 'delegate' class CiHash < DelegateClass(Hash) def initialize super({}) end def []=(k,v) __getobj__[(k.downcase rescue k)] = v end def [](k) __getobj__[(k.downcase rescue k)] end # add other lookup and mutation methods end > h = CiHash.new > h["FOO"]=1 > h[:not_a_string]=2 # works, too > puts h["foo"] > puts h[:not_a_string] > > Cheers > > robert -- use.inject do |as, often| as.you_can - without end