Class: Hash

Inherits:
Object
  • Object
show all
Defined in:
lib/monkey_patches.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(methodname, *args) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/monkey_patches.rb', line 4

def method_missing(methodname, *args)
  humps = methodname.to_s.split('_')
  key = humps.shift(1).first
  key = key + humps.map { |hump| hump.capitalize }.join if humps.length

  if self.include?(key)
    self[key]
  elsif key == 'id'
    "N/A"
  else
    super
  end
end