Class: CityGrid::Abstraction::SuperHash

Inherits:
Hash
  • Object
show all
Defined in:
lib/citygrid/abstraction/super_hash.rb

Direct Known Subclasses

CityGrid::API::Response, Item, Listing

Class Method Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *args, &block) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/citygrid/abstraction/super_hash.rb', line 12

def method_missing sym, *args, &block
  val = self[sym] || self[sym.to_s]

  # create new SuperHash if value is hash
  if val.is_a? Hash
    SuperHash.new val
  elsif val.is_a? Array
    SuperArray.new val
  elsif keys.include?(sym) || keys.include?(sym.to_s)
    val
  else
    super
  end
end

Class Method Details

.new(attrs) ⇒ Object



8
9
10
# File 'lib/citygrid/abstraction/super_hash.rb', line 8

def self.new attrs
  self[attrs]
end