mirror of
https://github.com/pry/pry.git
synced 2022-11-09 12:35:05 -05:00
added set_active_instance() method, added check to Pry.current_line += line to only append if expr is non-nil
This commit is contained in:
parent
8d63a4016a
commit
6ce8da2b06
1 changed files with 11 additions and 9 deletions
|
@ -180,27 +180,21 @@ class Pry
|
||||||
end
|
end
|
||||||
|
|
||||||
# save the pry instance to active_instance
|
# save the pry instance to active_instance
|
||||||
Pry.active_instance = self
|
set_active_instance(target)
|
||||||
target.eval("_pry_ = ::Pry.active_instance")
|
|
||||||
|
|
||||||
@last_result_is_exception = false
|
@last_result_is_exception = false
|
||||||
|
|
||||||
# eval the expression and save to last_result
|
|
||||||
# Do not want __FILE__, __LINE__ here because we need to distinguish
|
|
||||||
# (eval) methods for show-method and friends.
|
|
||||||
# This also sets the `_` local for the session.
|
|
||||||
expr = r(target)
|
expr = r(target)
|
||||||
|
|
||||||
Pry.line_buffer.push(*expr.each_line)
|
Pry.line_buffer.push(*expr.each_line)
|
||||||
result = set_last_result(target.eval(expr, "(pry)", Pry.current_line), target)
|
set_last_result(target.eval(expr, "(pry)", Pry.current_line), target)
|
||||||
result
|
|
||||||
rescue SystemExit => e
|
rescue SystemExit => e
|
||||||
exit
|
exit
|
||||||
rescue Exception => e
|
rescue Exception => e
|
||||||
@last_result_is_exception = true
|
@last_result_is_exception = true
|
||||||
set_last_exception(e, target)
|
set_last_exception(e, target)
|
||||||
ensure
|
ensure
|
||||||
Pry.current_line += expr.each_line.to_a.size
|
Pry.current_line += expr.each_line.count if expr
|
||||||
end
|
end
|
||||||
|
|
||||||
# Perform a read.
|
# Perform a read.
|
||||||
|
@ -299,6 +293,14 @@ class Pry
|
||||||
target.eval("_ex_ = ::Pry.last_exception")
|
target.eval("_ex_ = ::Pry.last_exception")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Set the active instance for a session.
|
||||||
|
# This method should not need to be invoked directly.
|
||||||
|
# @param [Binding] target The binding to set `_ex_` on.
|
||||||
|
def set_active_instance(target)
|
||||||
|
Pry.active_instance = self
|
||||||
|
target.eval("_pry_ = ::Pry.active_instance")
|
||||||
|
end
|
||||||
|
|
||||||
# @return [Boolean] True if the last result is an exception that was raised,
|
# @return [Boolean] True if the last result is an exception that was raised,
|
||||||
# as opposed to simply an instance of Exception (like the result of
|
# as opposed to simply an instance of Exception (like the result of
|
||||||
# Exception.new)
|
# Exception.new)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue