Method: Kernel#call_stack

Defined in:
lib/core/facets/kernel/callstack.rb

#call_stack(level = 1) ⇒ Object

Parse a caller string and break it into its components, returning an array. Returns:

  • file (String)

  • lineno (Integer)

  • method (Symbol)

For example, from irb,

call_stack(1)

produces

[[“(irb)”, 2, :irb_binding],

["/usr/lib/ruby/1.8/irb/workspace.rb", 52, :irb_binding],
["/usr/lib/ruby/1.8/irb/workspace.rb", 52, nil]]

Note: If the user decides to redefine caller() to output data in a different format, prior to requiring this, then the results will be indeterminate.

CREDIT: Trans


32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/core/facets/kernel/callstack.rb', line 32

def call_stack( level = 1 )
  call_str_array = pp_call_stack(level)
  stack = []
  call_str_array.each{ |call_str|
    file, lineno, method = call_str.split(':')
    if method =~ /in `(.*)'/ then
      method = $1.intern()
    end
    stack << [file, lineno.to_i, method]
  }
  stack
end