1
0
Fork 0
mirror of https://github.com/pry/pry.git synced 2022-11-09 12:35:05 -05:00
pry--pry/lib/pry/last_exception.rb
2014-03-09 19:39:01 -07:00

37 lines
752 B
Ruby

# LastException is a proxy used to add functionality to the `last_exception`
# attribute of Pry instances.
class Pry::LastException < BasicObject
attr_reader :file, :line
attr_accessor :bt_index
def initialize(e)
@e = e
@bt_index = 0
@file, @line = bt_source_location_for(0)
end
def method_missing(name, *args, &block)
if @e.respond_to?(name)
@e.public_send(name, *args, &block)
else
super
end
end
def respond_to_missing?(name, include_private = false)
@e.respond_to?(name)
end
def wrapped_exception
@e
end
def bt_source_location_for(index)
backtrace[index] =~ /(.*):(\d+)/
[$1, $2.to_i]
end
def inc_bt_index
@bt_index = (@bt_index + 1) % backtrace.size
end
end