Class: BackgroundQueue::Utils::AnyKeyHash
- Inherits:
-
Object
- Object
- BackgroundQueue::Utils::AnyKeyHash
- Defined in:
- lib/background_queue/utils.rb
Overview
class that wraps a hash so it can be accessed by key or symbol
Instance Attribute Summary collapse
-
#hash ⇒ Object
the wrapped hash.
Instance Method Summary collapse
-
#[](key) ⇒ Object
get an entry by string or symbol.
- #[]=(key, value) ⇒ Object
-
#initialize(hash) ⇒ AnyKeyHash
constructor
wrap a hash.
- #merge(other_map) ⇒ Object
- #to_json(dummy = true) ⇒ Object
Constructor Details
#initialize(hash) ⇒ AnyKeyHash
wrap a hash
38 39 40 41 42 43 44 |
# File 'lib/background_queue/utils.rb', line 38 def initialize(hash) if hash.kind_of?(Hash) @hash = hash else raise "Invalid class used when initializing AnyKeyHash (#{hash.class.name})" end end |
Instance Attribute Details
#hash ⇒ Object
the wrapped hash
35 36 37 |
# File 'lib/background_queue/utils.rb', line 35 def hash @hash end |
Instance Method Details
#[](key) ⇒ Object
get an entry by string or symbol
47 48 49 |
# File 'lib/background_queue/utils.rb', line 47 def [] (key) BackgroundQueue::Utils.get_hash_entry(@hash, key) end |
#[]=(key, value) ⇒ Object
51 52 53 |
# File 'lib/background_queue/utils.rb', line 51 def []=(key, value) @hash[key] = value end |
#merge(other_map) ⇒ Object
59 60 61 |
# File 'lib/background_queue/utils.rb', line 59 def merge(other_map) AnyKeyHash.new(@hash.clone.update(other_map)) end |
#to_json(dummy = true) ⇒ Object
55 56 57 |
# File 'lib/background_queue/utils.rb', line 55 def to_json(dummy=true) @hash.to_json end |