• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/ruby
2
3unless defined? Call
4
5Call = Struct.new( :file, :line, :method )
6class Call
7
8  def self.parse( call_string )
9    parts = call_string.split( ':', 3 )
10    file = parts.shift
11    line = parts.shift.to_i
12    if parts.empty?
13        return Call.new( file, line )
14    else
15        mstring = parts.shift
16        match = mstring.match( /`(.+)'/ )
17        method = match ? match[ 1 ] : nil
18        return Call.new( file, line, method )
19    end
20  end
21
22  def self.convert_backtrace( trace )
23    trace.map { |c| parse c }
24  end
25
26  def irb?
27    self.file == '(irb)'
28  end
29
30  def e_switch?
31    self.file == '-e'
32  end
33
34  def to_s
35    string = '%s:%i' % [ file, line ]
36    method and string << ":in `%s'" % method
37    return( string )
38  end
39
40  def inspect
41    to_s.inspect
42  end
43end
44
45module Kernel
46  def call_stack( depth = 1 )
47    Call.convert_backtrace( caller( depth + 1 ) )
48  end
49end
50
51class Exception
52  def backtrace!
53    Call.convert_backtrace( backtrace )
54  end
55end
56
57end # unless defined? Call
58