Class: BackgroundQueue::Utils::AnyKeyHash

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#hashObject

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