Method: Kernel#callstack
- Defined in:
- lib/garcon/core_ext/kernel.rb
#callstack(level = 1) ⇒ Object Also known as: call_stack
Parse a caller string and break it into its components, returning an array composed of:
-
file (String)
-
lineno (Integer)
-
method (Symbol)
For example, from irb
callstack(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.
142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/garcon/core_ext/kernel.rb', line 142 def callstack(level = 1) call_str_array = pp_callstack(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 |