Sha256: 20f00cae9cb5736e3032caa53e8933328febfba405c517cd24728c6f7b1cacfb

Contents?: true

Size: 1.31 KB

Versions: 6

Compression:

Stored size: 1.31 KB

Contents

# frozen_string_literal: true

# :nodoc:

# See {Module}
# @api private
class Module
  # @api private
  # :nodoc:
  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 unless method_defined?(:silence_redefinition_of_method)

  # Replaces the existing method definition, if there is one, with the passed
  # block as its body.
  # @api private
  # :nodoc:
  def redefine_method(method, &block)
    visibility = method_visibility(method)
    silence_redefinition_of_method(method)
    define_method(method, &block)
    send(visibility, method)
  end unless method_defined?(:redefine_method)

  # Replaces the existing singleton method definition, if there is one, with
  # the passed block as its body.
  # @api private
  # :nodoc:
  def redefine_singleton_method(method, &block)
    singleton_class.redefine_method(method, &block)
  end unless method_defined?(:redefine_singleton_method)

  # @api private
  # :nodoc:
  def method_visibility(method) # :nodoc:
    case
    when private_method_defined?(method)
      :private
    when protected_method_defined?(method)
      :protected
    else
      :public
    end
  end unless method_defined?(:method_visibility)
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
stub_requests-0.1.11 lib/stub_requests/core_ext/module/redefine_method.rb
stub_requests-0.1.10 lib/stub_requests/core_ext/module/redefine_method.rb
stub_requests-0.1.9 lib/stub_requests/core_ext/module/redefine_method.rb
stub_requests-0.1.8 lib/stub_requests/core_ext/module/redefine_method.rb
stub_requests-0.1.7 lib/stub_requests/core_ext/module/redefine_method.rb
stub_requests-0.1.6 lib/stub_requests/core_ext/module/redefine_method.rb