class Buckaruby::Support::CaseInsensitiveHash

The case insensitive Hash is a Hash with case insensitive keys that can also be accessed by using a Symbol.

Public Class Methods

new(constructor = {}) click to toggle source
Calls superclass method
# File lib/buckaruby/support/case_insensitive_hash.rb, line 8
def initialize(constructor = {})
  if constructor.is_a?(Hash)
    super()
    update(constructor)
  else
    super(constructor)
  end
end

Public Instance Methods

[](key) click to toggle source
Calls superclass method
# File lib/buckaruby/support/case_insensitive_hash.rb, line 17
def [](key)
  super(convert_key(key))
end
[]=(key, value) click to toggle source
Calls superclass method
# File lib/buckaruby/support/case_insensitive_hash.rb, line 21
def []=(key, value)
  super(convert_key(key), value)
end

Protected Instance Methods

convert_key(key) click to toggle source
# File lib/buckaruby/support/case_insensitive_hash.rb, line 31
def convert_key(key)
  string = key.is_a?(Symbol) ? key.to_s : key
  string.downcase
end
update(hash) click to toggle source
# File lib/buckaruby/support/case_insensitive_hash.rb, line 27
def update(hash)
  hash.each_pair { |key, value| self[convert_key(key)] = value }
end