1
0
Fork 0
mirror of https://github.com/pry/pry.git synced 2022-11-09 12:35:05 -05:00

MethodPatcher#with_method_transactions: alias --> alias_method

This commit is contained in:
John Mair 2013-01-02 17:52:37 +01:00
parent e647957507
commit ef8b71a09c

View file

@ -45,16 +45,19 @@ class Pry
# #
# @param [String] meth_name The method name before aliasing # @param [String] meth_name The method name before aliasing
# @param [Module] target The owner of the method # @param [Module] target The owner of the method
def with_method_transaction
target = owner_binding
temp_name = "__pry_#{code_object.original_name}__"
target.eval("alias #{temp_name} #{code_object.original_name}") def with_method_transaction
temp_name = "__pry_#{code_object.original_name}__"
co = code_object
code_object.owner.class_eval do
alias_method temp_name, co.original_name
yield yield
target.eval("alias #{code_object.name} #{code_object.original_name}") alias_method co.name, co.original_name
target.eval("alias #{code_object.original_name} #{temp_name}") alias_method co.original_name, temp_name
end
ensure ensure
target.eval("undef #{temp_name}") rescue nil co.send(:remove_method, temp_name) rescue nil
end end
# Update the definition line so that it can be eval'd directly on the Method's # Update the definition line so that it can be eval'd directly on the Method's
@ -77,12 +80,6 @@ class Pry
end end
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` # Apply wrap_for_owner and wrap_for_nesting successively to `source`
# @param [String] source # @param [String] source
# @return [String] The wrapped source. # @return [String] The wrapped source.