Class: Longleaf::CaseInsensitiveHash

Inherits:
Hash
  • Object
show all
Defined in:
lib/longleaf/helpers/case_insensitive_hash.rb

Overview

Hash subclass which provides case insensitive keys, where keys are always downcased.

Instance Method Summary collapse

Instance Method Details

#[](key) ⇒ Object



4
5
6
# File 'lib/longleaf/helpers/case_insensitive_hash.rb', line 4

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

#[]=(key, value) ⇒ Object



8
9
10
# File 'lib/longleaf/helpers/case_insensitive_hash.rb', line 8

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

#delete(key) ⇒ Object



12
13
14
# File 'lib/longleaf/helpers/case_insensitive_hash.rb', line 12

def delete(key)
  super _insensitive(key)
end

#encode_with(coder) ⇒ Object

Cause this hash to serialize as a regular hash to avoid deserialization failures



29
30
31
# File 'lib/longleaf/helpers/case_insensitive_hash.rb', line 29

def encode_with coder
  coder.represent_map nil, self
end

#has_key?(key) ⇒ Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/longleaf/helpers/case_insensitive_hash.rb', line 16

def has_key?(key)
  super _insensitive(key)
end

#merge(other_hash) ⇒ Object



20
21
22
# File 'lib/longleaf/helpers/case_insensitive_hash.rb', line 20

def merge(other_hash)
  super other_hash.map {|k, v| [_insensitive(k), v] }.to_h
end

#merge!(other_hash) ⇒ Object



24
25
26
# File 'lib/longleaf/helpers/case_insensitive_hash.rb', line 24

def merge!(other_hash)
  super other_hash.map {|k, v| [_insensitive(k), v] }.to_h
end