Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A Hash that will ignore the casing of string keys, and treat string and symbol keys synonymously.
class CaseInsensitiveHash
def initialize
@hsh = {}
end
def get(key)
raise ArgumentError unless key.respond_to?(:to_s)
@hsh[key.to_s.downcase.to_sym]
end
def set(key, value)
raise ArgumentError unless key.respond_to?(:to_s)
actual_key = key.to_s.downcase.to_sym
@hsh[actual_key] = value
end
alias [] get
alias []= set
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.