Sha256: 197b75e3e20fefff3820bbf405b6bbb0de7c0e1e09341762f2ccbbca161d00eb

Contents?: true

Size: 1.06 KB

Versions: 10

Compression:

Stored size: 1.06 KB

Contents

module Kernel

  alias_method :pp_callstack, :caller

  # 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

  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

end


class Binding

  # Returns the call stack, in array format.

  def callstack(level=1)
    eval( "callstack( #{level} )" )
  end

end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
facets-2.8.4 lib/core/facets/kernel/callstack.rb
facets-2.8.3 lib/core/facets/kernel/callstack.rb
facets-2.8.2 lib/core/facets/kernel/callstack.rb
facets-2.8.1 lib/core/facets/kernel/callstack.rb
facets-2.8.0 lib/core/facets/kernel/callstack.rb
facets-2.7.0 lib/core/facets/kernel/callstack.rb
facets-2.6.0 lib/core/facets/kernel/callstack.rb
facets-2.5.1 lib/core/facets/kernel/callstack.rb
facets-2.5.0 lib/core/facets/kernel/callstack.rb
facets-2.5.2 lib/core/facets/kernel/callstack.rb