class Module

copied from activesupport/core_ext from Rails, MIT license github.com/rails/rails/tree/a713fdae4eb4f7ccd34932edc61561a96b8d9f35/activesupport/lib/active_support/core_ext/module

Public Instance Methods

redefine_method(method, &block) click to toggle source

Replaces the existing method definition, if there is one, with the passed block as its body.

   # File lib/dbus/core_ext/module/redefine_method.rb
28 def redefine_method(method, &block)
29   visibility = method_visibility(method)
30   silence_redefinition_of_method(method)
31   define_method(method, &block)
32   send(visibility, method)
33 end
redefine_singleton_method(method, &block) click to toggle source

Replaces the existing singleton method definition, if there is one, with the passed block as its body.

   # File lib/dbus/core_ext/module/redefine_method.rb
37 def redefine_singleton_method(method, &block)
38   singleton_class.redefine_method(method, &block)
39 end
silence_redefinition_of_method(method) click to toggle source

Marks the named method as intended to be redefined, if it exists. Suppresses the Ruby method redefinition warning. Prefer redefine_method where possible.

   # File lib/dbus/core_ext/module/redefine_method.rb
10 def silence_redefinition_of_method(method)
11   if method_defined?(method) || private_method_defined?(method)
12     # This suppresses the "method redefined" warning; the self-alias
13     # looks odd, but means we don't need to generate a unique name
14     alias_method method, method
15   end
16 end