Class: Module
- Inherits:
-
Object
- Object
- Module
- Defined in:
- lib/apple_core/extensions/module.rb
Overview
Instance Method Summary collapse
-
#redefine_method(method, &block) ⇒ Object
Replaces the existing method definition, if there is one, with the passed block as its body.
- #remove_possible_method(method) ⇒ Object
-
#remove_possible_singleton_method(method) ⇒ Object
Removes the named singleton method, if it exists.
Instance Method Details
#redefine_method(method, &block) ⇒ Object
Replaces the existing method definition, if there is one, with the passed block as its body.
23 24 25 26 |
# File 'lib/apple_core/extensions/module.rb', line 23 def redefine_method(method, &block) remove_possible_method(method) define_method(method, &block) end |
#remove_possible_method(method) ⇒ Object
8 9 10 11 12 |
# File 'lib/apple_core/extensions/module.rb', line 8 def remove_possible_method(method) return unless method_defined?(method) || private_method_defined?(method) undef_method(method) end |
#remove_possible_singleton_method(method) ⇒ Object
Removes the named singleton method, if it exists.
15 16 17 18 19 |
# File 'lib/apple_core/extensions/module.rb', line 15 def remove_possible_singleton_method(method) singleton_class.instance_eval do remove_possible_method(method) end end |