Permalink
Browse files

Move raise-up impl out of the middle of the REPL methods

  • Loading branch information...
1 parent 10b2238 commit b7112667ef93412b893682e5025e56c1d7bfb876 @rf- rf- committed Mar 18, 2012
Showing with 42 additions and 43 deletions.
  1. +42 −43 lib/pry/pry_instance.rb
View
@@ -266,48 +266,6 @@ def re(target=TOPLEVEL_BINDING)
exec_hook :after_eval, result, self
end
- # Raise an exception out of Pry.
- #
- # See Kernel#raise for documentation of parameters.
- # See rb_make_exception for the inbuilt implementation.
- #
- # This is necessary so that the raise-up command can tell the
- # difference between an exception the user has decided to raise,
- # and a mistake in specifying that exception.
- #
- # (i.e. raise-up RunThymeError.new should not be the same as
- # raise-up NameError, "unititialized constant RunThymeError")
-
- def raise_up_common(force, *args)
- exception = if args == []
- last_exception || RuntimeError.new
- elsif args.length == 1 && args.first.is_a?(String)
- RuntimeError.new(args.first)
- elsif args.length > 3
- raise ArgumentError, "wrong number of arguments"
- elsif !args.first.respond_to?(:exception)
- raise TypeError, "exception class/object expected"
- elsif args.length === 1
- args.first.exception
- else
- args.first.exception(args[1])
- end
-
- raise TypeError, "exception object expected" unless exception.is_a? Exception
-
- exception.set_backtrace(args.length === 3 ? args[2] : caller(1))
-
- if force || binding_stack.one?
- binding_stack.clear
- throw :raise_up, exception
- else
- binding_stack.pop
- raise exception
- end
- end
- def raise_up(*args); raise_up_common(false, *args); end
- def raise_up!(*args); raise_up_common(true, *args); end
-
# Perform a read.
# If no parameter is given, default to top-level (main).
# This is a multi-line read; so the read continues until a valid
@@ -566,7 +524,6 @@ def handle_read_errors
retry
end
end
-
private :handle_read_errors
# Returns the next line of input to be used by the pry instance.
@@ -694,4 +651,46 @@ def incomplete_user_input_exception?(ex)
false
end
end
+
+ # Raise an exception out of Pry.
+ #
+ # See Kernel#raise for documentation of parameters.
+ # See rb_make_exception for the inbuilt implementation.
+ #
+ # This is necessary so that the raise-up command can tell the
+ # difference between an exception the user has decided to raise,
+ # and a mistake in specifying that exception.
+ #
+ # (i.e. raise-up RunThymeError.new should not be the same as
+ # raise-up NameError, "unititialized constant RunThymeError")
+ #
+ def raise_up_common(force, *args)
+ exception = if args == []
+ last_exception || RuntimeError.new
+ elsif args.length == 1 && args.first.is_a?(String)
+ RuntimeError.new(args.first)
+ elsif args.length > 3
+ raise ArgumentError, "wrong number of arguments"
+ elsif !args.first.respond_to?(:exception)
+ raise TypeError, "exception class/object expected"
+ elsif args.length === 1
+ args.first.exception
+ else
+ args.first.exception(args[1])
+ end
+
+ raise TypeError, "exception object expected" unless exception.is_a? Exception
+
+ exception.set_backtrace(args.length === 3 ? args[2] : caller(1))
+
+ if force || binding_stack.one?
+ binding_stack.clear
+ throw :raise_up, exception
+ else
+ binding_stack.pop
+ raise exception
+ end
+ end
+ def raise_up(*args); raise_up_common(false, *args); end
+ def raise_up!(*args); raise_up_common(true, *args); end
end

0 comments on commit b711266

Please sign in to comment.