Class: Object
- Inherits:
- BasicObject
- Defined in:
- lib/define-method/module_ext.rb
Instance Attribute Summary collapse
-
#define_method_blocks ⇒ Object
Returns the value of attribute define_method_blocks.
Instance Method Summary collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/define-method/module_ext.rb', line 17 def method_missing(method, *args, &block) if $define_method_blocks[self.class.to_s] && $define_method_blocks[self.class.to_s].include?(method) return $define_method_blocks[self.class.to_s][method].call(*args) elsif self.respond_to?(:metaclass) && $define_method_blocks[self..to_s] && $define_method_blocks[self..to_s].include?(method) return $define_method_blocks[self..to_s][method].call(*args) else self.class.ancestors.each do |clazz| if $define_method_blocks[clazz.to_s] && $define_method_blocks[clazz.to_s].include?(method) return $define_method_blocks[clazz.to_s][method].call(*args) end end return original_module_method_missing(method, *args) end end |
Instance Attribute Details
#define_method_blocks ⇒ Object
Returns the value of attribute define_method_blocks.
15 16 17 |
# File 'lib/define-method/module_ext.rb', line 15 def define_method_blocks @define_method_blocks end |
Instance Method Details
#original_module_method_missing ⇒ Object
16 |
# File 'lib/define-method/module_ext.rb', line 16 alias_method :original_module_method_missing, :method_missing |