Sha256: f9a7128f2c69751c9771bd01b92b21f8fa5f4885d8dee4f0edcd81ef70cd70da

Contents?: true

Size: 1.19 KB

Versions: 9

Compression:

Stored size: 1.19 KB

Contents

module Kernel

  alias_method :pp_callstack, :caller
  alias_method :pp_call_stack, :caller

  # 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
  #
  #   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

  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

  alias_method :callstack, :call_stack

end


class Binding

  # Returns the call stack, in array format.
  def call_stack(level=1)
    eval( "callstack( #{level} )" )
  end

  alias_method :callstack, :call_stack
end

Version data entries

9 entries across 8 versions & 2 rubygems

Version Path
gorillib-0.4.0pre lib/alt/kernel/call_stack.rb
gorillib-0.4.1pre lib/alt/kernel/call_stack.rb
facets-2.9.3 lib/core/facets/kernel/call_stack.rb
facets-2.9.2 lib/core/facets/kernel/call_stack.rb
facets-2.9.2 src/core/facets/kernel/call_stack.rb
facets-2.9.1 lib/core/facets/kernel/call_stack.rb
facets-2.9.0 lib/core/facets/kernel/call_stack.rb
facets-2.9.0.pre.2 lib/core/facets/kernel/call_stack.rb
facets-2.9.0.pre.1 lib/core/facets/kernel/call_stack.rb