Class: Coderwall::Hash

Inherits:
Hash
  • Object
show all
Defined in:
lib/coderwall-api/hash.rb

Instance Method Summary collapse

Constructor Details

#initialize(hash = {}) ⇒ Hash

Returns a new instance of Hash.



3
4
5
6
7
8
9
# File 'lib/coderwall-api/hash.rb', line 3

def initialize(hash = {})
  hash.keys.each do |key|
    value = hash[key]
    value = Coderwall::Hash.new(value) if value.is_a?(::Hash)
    self[key.to_sym] = value
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/coderwall-api/hash.rb', line 11

def method_missing(method_name, *args)
  if key?(method_name.to_sym)
    self[method_name.to_sym]
  else
    super
  end
end