Module: IndiferentHash
- Defined in:
- lib/rbbt/util/misc/indiferent_hash.rb
Class Method Summary collapse
Instance Method Summary collapse
- #[](key) ⇒ Object
- #delete(key) ⇒ Object
- #include?(key) ⇒ Boolean
- #merge(other) ⇒ Object
- #values_at(*key_list) ⇒ Object
Class Method Details
.setup(hash) ⇒ Object
3 4 5 |
# File 'lib/rbbt/util/misc/indiferent_hash.rb', line 3 def self.setup(hash) hash.extend IndiferentHash end |
Instance Method Details
#[](key) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/rbbt/util/misc/indiferent_hash.rb', line 17 def [](key) res = super(key) return res unless res.nil? case key when Symbol, Module super(key.to_s) when String super(key.to_sym) else super(key) end end |
#delete(key) ⇒ Object
46 47 48 49 50 51 52 53 54 55 |
# File 'lib/rbbt/util/misc/indiferent_hash.rb', line 46 def delete(key) case key when Symbol, Module super(key) || super(key.to_s) when String super(key) || super(key.to_sym) else super(key) end end |
#include?(key) ⇒ Boolean
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/rbbt/util/misc/indiferent_hash.rb', line 35 def include?(key) case key when Symbol, Module super(key) || super(key.to_s) when String super(key) || super(key.to_sym) else super(key) end end |
#merge(other) ⇒ Object
7 8 9 10 11 12 13 14 15 |
# File 'lib/rbbt/util/misc/indiferent_hash.rb', line 7 def merge(other) new = self.dup IndiferentHash.setup(new) other.each do |k,value| new.delete k new[k] = value end new end |
#values_at(*key_list) ⇒ Object
31 32 33 |
# File 'lib/rbbt/util/misc/indiferent_hash.rb', line 31 def values_at(*key_list) key_list.inject([]){|acc,key| acc << self[key]} end |