Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

MethodPatcher#with_method_transactions: alias --> alias_method

  • Loading branch information...
commit ef8b71a09c0b3a93d861a9f333e1ee1d22e28d0e 1 parent e647957
John Mair banister authored
Showing with 9 additions and 12 deletions.
  1. +9 −12 lib/pry/commands/edit/method_patcher.rb
21 lib/pry/commands/edit/method_patcher.rb
View
@@ -45,16 +45,19 @@ def adjusted_lines
#
# @param [String] meth_name The method name before aliasing
# @param [Module] target The owner of the method
+
def with_method_transaction
- target = owner_binding
temp_name = "__pry_#{code_object.original_name}__"
+ co = code_object
+ code_object.owner.class_eval do
+ alias_method temp_name, co.original_name
+ yield
+ alias_method co.name, co.original_name
+ alias_method co.original_name, temp_name
+ end
- target.eval("alias #{temp_name} #{code_object.original_name}")
- yield
- target.eval("alias #{code_object.name} #{code_object.original_name}")
- target.eval("alias #{code_object.original_name} #{temp_name}")
ensure
- target.eval("undef #{temp_name}") rescue nil
+ co.send(:remove_method, temp_name) rescue nil
end
# Update the definition line so that it can be eval'd directly on the Method's
@@ -77,12 +80,6 @@ def definition_line_for_owner(line)
end
end
- # Provide a binding for the `code_object`'s owner context.
- # @return [Binding]
- def owner_binding
- Pry.binding_for(code_object.owner)
- end
-
# Apply wrap_for_owner and wrap_for_nesting successively to `source`
# @param [String] source
# @return [String] The wrapped source.
Please sign in to comment.
Something went wrong with that request. Please try again.