Class: IceCube::HashInput::Mash

Inherits:
Object
  • Object
show all
Defined in:
lib/ice_cube/hash_input.rb

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ Mash

Returns a new instance of Mash.



5
6
7
# File 'lib/ice_cube/hash_input.rb', line 5

def initialize(hash)
  @hash = hash
end

Instance Method Details

#[](key) ⇒ Object

Fetch values indifferently by symbol or string key without symbolizing arbitrary string input



12
13
14
15
16
17
18
19
# File 'lib/ice_cube/hash_input.rb', line 12

def [](key)
  @hash.fetch(key) do |key|
    str_key = key.to_s
    @hash.each_pair.detect do |sym_key, value|
      return value if sym_key.to_s == str_key
    end
  end
end