class ShellMock::MonkeyPatch

Public Instance Methods

disable() click to toggle source
# File lib/shell_mock/monkey_patch.rb, line 10
def disable
  disable_for(Kernel.eigenclass) if Kernel.respond_to?(method_alias, true)
  disable_for(Kernel)            if Object.new.respond_to?(method_alias, true)
end
enable() click to toggle source
# File lib/shell_mock/monkey_patch.rb, line 5
def enable
  enable_for(Kernel.eigenclass) unless Kernel.respond_to?(method_alias, true)
  enable_for(Kernel)            unless Object.new.respond_to?(method_alias, true)
end

Private Instance Methods

disable_for(class_or_module) click to toggle source
# File lib/shell_mock/monkey_patch.rb, line 37
def disable_for(class_or_module)
  begin
    # so we don't have to see method redefinition warnings
    class_or_module.send(:remove_method, method_name)
  rescue NameError
  end

  class_or_module.send(:alias_method, method_name, method_alias)

  begin
    class_or_module.send(:remove_method, method_alias)
  rescue NameError
  end
end
enable_for(class_or_module) click to toggle source
# File lib/shell_mock/monkey_patch.rb, line 25
def enable_for(class_or_module)
  class_or_module.send(:alias_method, method_alias, method_name)

  begin
    # so we don't have to see method redefinition warnings
    class_or_module.send(:remove_method, method_name)
  rescue NameError
  end

  class_or_module.send(:define_method, method_name, &method(:override))
end
interpolatable_name() click to toggle source
# File lib/shell_mock/monkey_patch.rb, line 21
def interpolatable_name
  method_name
end
method_alias() click to toggle source
# File lib/shell_mock/monkey_patch.rb, line 17
def method_alias
  "__un_shell_mocked_#{interpolatable_name}"
end