Class: Pry::LastException
- Inherits:
- BasicObject
- Defined in:
- lib/pry/last_exception.rb
Overview
LastException is a proxy class who wraps an Exception object for #last_exception. it extends the exception object with methods that help pry commands be useful.
the original exception object is not modified and method calls are forwarded to the wrapped exception object.
Instance Attribute Summary collapse
-
#bt_index ⇒ Object
Returns the value of attribute bt_index.
Instance Method Summary collapse
- #bt_source_location_for(index) ⇒ Object
-
#file ⇒ String
Returns the path to a file for the current backtrace.
- #inc_bt_index ⇒ Object
-
#initialize(e) ⇒ LastException
constructor
A new instance of LastException.
-
#line ⇒ Fixnum
Returns the line for the current backtrace.
- #method_missing(name, *args, &block) ⇒ Object
- #respond_to_missing?(name, include_private = false) ⇒ Boolean
-
#wrapped_exception ⇒ Exception
Returns the wrapped exception.
Constructor Details
#initialize(e) ⇒ LastException
Returns a new instance of LastException.
12 13 14 15 16 |
# File 'lib/pry/last_exception.rb', line 12 def initialize(e) @e = e @bt_index = 0 @file, @line = bt_source_location_for(0) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/pry/last_exception.rb', line 18 def method_missing(name, *args, &block) if @e.respond_to?(name) @e.public_send(name, *args, &block) else super end end |
Instance Attribute Details
#bt_index ⇒ Object
Returns the value of attribute bt_index.
10 11 12 |
# File 'lib/pry/last_exception.rb', line 10 def bt_index @bt_index end |
Instance Method Details
#bt_source_location_for(index) ⇒ Object
53 54 55 56 |
# File 'lib/pry/last_exception.rb', line 53 def bt_source_location_for(index) backtrace[index] =~ /(.*):(\d+)/ [$1, $2.to_i] end |
#file ⇒ String
Returns the path to a file for the current backtrace. see #bt_index.
34 35 36 |
# File 'lib/pry/last_exception.rb', line 34 def file @file end |
#inc_bt_index ⇒ Object
58 59 60 |
# File 'lib/pry/last_exception.rb', line 58 def inc_bt_index @bt_index = (@bt_index + 1) % backtrace.size end |
#line ⇒ Fixnum
Returns the line for the current backtrace. see #bt_index.
42 43 44 |
# File 'lib/pry/last_exception.rb', line 42 def line @line end |
#respond_to_missing?(name, include_private = false) ⇒ Boolean
26 27 28 |
# File 'lib/pry/last_exception.rb', line 26 def respond_to_missing?(name, include_private = false) @e.respond_to?(name) end |
#wrapped_exception ⇒ Exception
Returns the wrapped exception
49 50 51 |
# File 'lib/pry/last_exception.rb', line 49 def wrapped_exception @e end |