Pastie now auto-senses if line-wrap is a bad or good idea. Feedback?
## mark a section (Learn more)
#-- # Copyright 2007 by Stefan Rusterholz. # All rights reserved. # See LICENSE.txt for permissions. #++ # The same as hash, except that keys are normalized # before all operations, which allows to e.g. create # a case insensitive hash or a hash that doesn't differ # between strings and symbols... class NormalizedHash < Hash def [](key) super(normalize(key)) end def []=(key, value) super(normalize(key), value) end def has_key?(key) super(normalize(key)) end def values_at(*keys) super(*keys.map{ |m| normalize(m) }) end def merge(hash) result = self.dup result.merge!(hash) result end def merge!(hash) hash.each { |key, value| self[key] = value } end def normalize(key) key end end
This paste will be private.
From the Design Piracy series on my blog: