Class: IndifferentHash

Inherits:
Hash
  • Object
show all
Defined in:
lib/pipeline_toolkit/util/indifferent_hash.rb

Instance Method Summary collapse

Methods inherited from Hash

#except_keys, #select_keys

Constructor Details

#initialize(hash) ⇒ IndifferentHash

extended so that value is returned regardless if key is symbol or string, and all values are set as symbols



3
4
5
# File 'lib/pipeline_toolkit/util/indifferent_hash.rb', line 3

def initialize(hash)
  self.merge!( Hash[hash.map { |k,v| [k.to_sym, v] }] )
end

Instance Method Details

#[](key) ⇒ Object



7
8
9
# File 'lib/pipeline_toolkit/util/indifferent_hash.rb', line 7

def [](key)
  super(key.to_sym)
end

#[]=(key, value) ⇒ Object



11
12
13
# File 'lib/pipeline_toolkit/util/indifferent_hash.rb', line 11

def []=(key, value)
  super(key.to_sym, value)
end

#has_key?(key) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/pipeline_toolkit/util/indifferent_hash.rb', line 19

def has_key?(key)
  super(key.to_sym)  
end

#keys_and_values_as_stringsObject



15
16
17
# File 'lib/pipeline_toolkit/util/indifferent_hash.rb', line 15

def keys_and_values_as_strings
  Hash[self.map { |k,v| [k.to_s, v.to_s] }]
end