Module: Candy::Factory
- Defined in:
- lib/candy/factory.rb
Overview
Utility methods that can generate new methods or classes for some of Candy’s magic.
Class Method Summary collapse
-
.magic_method(klass, method, params = '') ⇒ Object
Creates a method with the same name as a provided class, in the same namespace as that class, which delegates to a given class method of that class.
Class Method Details
.magic_method(klass, method, params = '') ⇒ Object
Creates a method with the same name as a provided class, in the same namespace as that class, which delegates to a given class method of that class. (Whew. Make sense?)
9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/candy/factory.rb', line 9 def self.magic_method(klass, method, params='') ns = namespace(klass) my_name = klass.name.sub(ns, '').to_sym parent = (ns == '' ? Object : qualified_const_get(ns)) unless parent.method_defined?(my_name) parent.class_eval " def \#{my_name}(\#{params})\n \#{klass}.\#{method}(\#{params.gsub(/\\s?=(.+?),/,',')})\n end\n CLASS\n end\nend\n" |