Class: Wrest::HashWithCaseInsensitiveAccess

Inherits:
Hash
  • Object
show all
Defined in:
lib/wrest/hash_with_case_insensitive_access.rb

Overview

A hash with case-insensitive key access.

hash = Wrest::HashWithCaseInsensitiveAccess.new 'Abcd' => 1, 'xyz' => 2

hash['abcd']  #=> 1
hash['aBCd'] #=> 1

Instance Method Summary (collapse)

Methods included from CoreExt::Hash::Conversions

#mutate_using

Constructor Details

- (HashWithCaseInsensitiveAccess) initialize(hash = {})

:nodoc:



12
13
14
15
16
17
# File 'lib/wrest/hash_with_case_insensitive_access.rb', line 12

def initialize(hash={})
  super()
  hash.each do |key, value|
    self[convert_key(key)] = value
  end
end

Instance Method Details

- (Object) [](key)



18
19
20
# File 'lib/wrest/hash_with_case_insensitive_access.rb', line 18

def [](key)
  super(convert_key(key))
end

- (Object) []=(key, value)



22
23
24
# File 'lib/wrest/hash_with_case_insensitive_access.rb', line 22

def []=(key, value)
  super(convert_key(key), value)
end

- (Object) delete(key)



26
27
28
# File 'lib/wrest/hash_with_case_insensitive_access.rb', line 26

def delete(key)
  super(convert_key(key))
end

- (Object) merge(other)



34
35
36
# File 'lib/wrest/hash_with_case_insensitive_access.rb', line 34

def merge(other)
  dup.merge!(other)
end

- (Object) merge!(other)



38
39
40
41
42
43
# File 'lib/wrest/hash_with_case_insensitive_access.rb', line 38

def merge!(other)
  other.each do |key, value|
    self[convert_key(key)] = value
  end
  self
end

- (Object) values_at(*indices)



30
31
32
# File 'lib/wrest/hash_with_case_insensitive_access.rb', line 30

def values_at(*indices)
  indices.collect { |key| self[convert_key(key)] }
end