Class: String

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

Overview

This package installs method_missing handler to String class which handles to_xxxx_xxxx message to parse itself and convert into XxxxXxxx by sending parse message to XxxxXxxx class.

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



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

def method_missing(method, *arg, &block)
  method = method.to_s
  if method.slice!(0..2) == "to_"
    method.gsub!(%r{__}, '::_')
    method.gsub!(/\/(.?)/){"::" + $1.upcase}
    method.gsub!(/(^|_)(.)/){$2.upcase}
    mod = Object.module_eval(method, __FILE__, __LINE__)
    mod.parse(self, *arg, &block)
  else
    super
  end
end