Permalink
Browse files

exit and exit-all support return values

  • Loading branch information...
1 parent 7ce581e commit 73a568eac1df63045bcae055715de230857b7901 @banister banister committed Feb 25, 2011
Showing with 17 additions and 8 deletions.
  1. +7 −5 lib/pry/commands.rb
  2. +9 −2 lib/pry/pry_instance.rb
  3. +1 −1 lib/pry/version.rb
View
@@ -75,11 +75,12 @@ class Commands < CommandBase
output.puts "Pry version: #{Pry::VERSION} on Ruby #{RUBY_VERSION}."
end
- command "exit-all", "End all nested Pry sessions. Aliases: !!" do
- throw(:breakout, 0)
+ command "exit-all", "End all nested Pry sessions. Accepts optional return value. Aliases: @!" do
+ str = opts[:val].split.drop(1).join(' ')
+ throw(:breakout, [0, target.eval(str)])
end
- alias_command "!!", "exit-all", ""
+ alias_command "@!", "exit-all", ""
command "ls", "Show the list of vars in the current scope. Type `ls --help` for more info." do |*args|
options = {}
@@ -465,8 +466,9 @@ class Commands < CommandBase
end
end
- command "exit", "End the current Pry session. Aliases: quit, back" do
- throw(:breakout, opts[:nesting].level)
+ command "exit", "End the current Pry session. Accepts optional return value. Aliases: quit, back" do
+ str = opts[:val].split.drop(1).join(' ')
+ throw(:breakout, [opts[:nesting].level, target.eval(str)])
end
alias_command "quit", "exit", ""
@@ -86,7 +86,7 @@ def repl(target=TOPLEVEL_BINDING)
target.eval("_pry_ = Pry.active_instance")
target.eval("_ = Pry.last_result")
- break_level = catch(:breakout) do
+ break_data = catch(:breakout) do
nesting.push [nesting.size, target_self, self]
loop do
rep(target)
@@ -97,11 +97,18 @@ def repl(target=TOPLEVEL_BINDING)
exec_hook :after_session, output, target_self
+ # If break_data is an array, then the last element is the return value
+ break_level, return_value = Array(break_data)
+
# keep throwing until we reach the desired nesting level
if nesting_level != break_level
- throw :breakout, break_level
+ throw :breakout, break_data
end
+ # if one was provided, return the return value
+ return return_value if return_value
+
+ # otherwise return the target_self
target_self
end
View
@@ -1,3 +1,3 @@
class Pry
- VERSION = "0.6.1pro1"
+ VERSION = "0.6.1pro3"
end

0 comments on commit 73a568e

Please sign in to comment.