Module: CaseInsensitiveHash

Defined in:
lib/scout/indiferent_hash/case_insensitive.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.setup(hash) ⇒ Object



3
4
5
# File 'lib/scout/indiferent_hash/case_insensitive.rb', line 3

def self.setup(hash)
  hash.extend CaseInsensitiveHash
end

Instance Method Details

#[](key, *rest) ⇒ Object



17
18
19
20
21
22
# File 'lib/scout/indiferent_hash/case_insensitive.rb', line 17

def [](key, *rest)
  value = super(key, *rest)
  return value unless value.nil?
  key_downcase = key.to_s.downcase
  super(downcase_keys[key_downcase])
end

#downcase_keysObject



7
8
9
10
11
12
13
14
15
# File 'lib/scout/indiferent_hash/case_insensitive.rb', line 7

def downcase_keys
  @downcase_keys ||= begin
                       down = {} 
                       keys.collect{|key| 
                         down[key.to_s.downcase] = key 
                       }
                       down
                     end
end

#values_at(*keys) ⇒ Object



24
25
26
27
28
# File 'lib/scout/indiferent_hash/case_insensitive.rb', line 24

def values_at(*keys)
  keys.collect do |key|
    self[key]
  end
end