Class: Module Private
- Defined in:
- lib/stub_requests/core_ext/module/redefine_method.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
See Module
Instance Method Summary collapse
-
#method_visibility(method) ⇒ Object
private
:nodoc:.
-
#redefine_method(method, &block) ⇒ Object
private
Replaces the existing method definition, if there is one, with the passed block as its body.
-
#redefine_singleton_method(method, &block) ⇒ Object
private
Replaces the existing singleton method definition, if there is one, with the passed block as its body.
-
#silence_redefinition_of_method(method) ⇒ Object
private
:nodoc:.
Instance Method Details
#method_visibility(method) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
:nodoc:
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/stub_requests/core_ext/module/redefine_method.rb', line 38 def method_visibility(method) # :nodoc: case when private_method_defined?(method) :private when protected_method_defined?(method) :protected else :public end end |
#redefine_method(method, &block) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Replaces the existing method definition, if there is one, with the passed block as its body. :nodoc:
21 22 23 24 25 26 |
# File 'lib/stub_requests/core_ext/module/redefine_method.rb', line 21 def redefine_method(method, &block) visibility = method_visibility(method) silence_redefinition_of_method(method) define_method(method, &block) send(visibility, method) end |
#redefine_singleton_method(method, &block) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Replaces the existing singleton method definition, if there is one, with the passed block as its body. :nodoc:
32 33 34 |
# File 'lib/stub_requests/core_ext/module/redefine_method.rb', line 32 def redefine_singleton_method(method, &block) singleton_class.redefine_method(method, &block) end |
#silence_redefinition_of_method(method) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
:nodoc:
10 11 12 13 14 15 |
# File 'lib/stub_requests/core_ext/module/redefine_method.rb', line 10 def silence_redefinition_of_method(method) if method_defined?(method) || private_method_defined?(method) alias_method :__stub_requests_redefine, method remove_method :__stub_requests_redefine end end |