Class: Messagebus::DottableHash

Inherits:
Hash
  • Object
show all
Defined in:
lib/messagebus/dottable_hash.rb

Instance Method Summary collapse

Constructor Details

#initialize(plain_old_hash = {}) ⇒ DottableHash

Returns a new instance of DottableHash.



34
35
36
# File 'lib/messagebus/dottable_hash.rb', line 34

def initialize(plain_old_hash={})
  merge!(plain_old_hash)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *arguments, &block) ⇒ Object



42
43
44
45
46
47
48
49
# File 'lib/messagebus/dottable_hash.rb', line 42

def method_missing(method, *arguments, &block)
  key = method.to_s
  if key.match(/\=$/)
    self[key.chop] = arguments.first
  elsif self.has_key?(key)
    self[key]
  end
end

Instance Method Details

#[](key) ⇒ Object



51
52
53
# File 'lib/messagebus/dottable_hash.rb', line 51

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

#[]=(key, value) ⇒ Object Also known as: store



55
56
57
# File 'lib/messagebus/dottable_hash.rb', line 55

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

#assoc(key) ⇒ Object



79
80
81
# File 'lib/messagebus/dottable_hash.rb', line 79

def assoc(key)
  super(key.to_s)
end

#delete(key) ⇒ Object



67
68
69
# File 'lib/messagebus/dottable_hash.rb', line 67

def delete(key)
  super(key.to_s)
end

#fetch(key) ⇒ Object



75
76
77
# File 'lib/messagebus/dottable_hash.rb', line 75

def fetch(key)
  super(key.to_s)
end

#has_key?(key) ⇒ Boolean Also known as: key?, include?

Returns:

  • (Boolean)


71
72
73
# File 'lib/messagebus/dottable_hash.rb', line 71

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

#merge!(hash) ⇒ Object Also known as: update, merge



59
60
61
# File 'lib/messagebus/dottable_hash.rb', line 59

def merge!(hash)
  super(stringify_keys(hash))
end

#replace(hash) ⇒ Object



63
64
65
# File 'lib/messagebus/dottable_hash.rb', line 63

def replace(hash)
  super(stringify_keys(hash))
end

#respond_to?(method) ⇒ Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/messagebus/dottable_hash.rb', line 38

def respond_to?(method)
  true
end

#values_at(*args) ⇒ Object



83
84
85
# File 'lib/messagebus/dottable_hash.rb', line 83

def values_at(*args)
  super(*args.collect(&:to_s))
end