Sha256: 0eb5f7c365bdd9c23c7f50c40d06b16a9cbe33fbe199c127e43dcab886134f77

Contents?: true

Size: 1.17 KB

Versions: 26

Compression:

Stored size: 1.17 KB

Contents

module Kernel

  # 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.
  alias_method :pp_call_stack, :caller
  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

end



#  _____         _
# |_   _|__  ___| |_
#   | |/ _ \/ __| __|
#   | |  __/\__ \ |_
#   |_|\___||___/\__|
#
=begin test

  require 'test/unit'

  class TCKernel < Test::Unit::TestCase

    def test_call_stack
      assert_nothing_raised{ call_stack }
    end

  end

=end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
facets-0.9.0 lib/nano/kernel/call_stack.rb
facets-1.0.0 lib/facet/kernel/call_stack.rb
facets-1.0.3 packages/core/lib/facet/kernel/call_stack.rb
facets-1.2.0 lib/facets/core/kernel/call_stack.rb
facets-1.3.0 lib/facets/core/kernel/call_stack.rb
facets-1.1.0 lib/facet/kernel/call_stack.rb
facets-1.2.1 lib/facets/core/kernel/call_stack.rb
facets-1.3.2 lib/facets/core/kernel/call_stack.rb
facets-1.3.3 lib/facets/core/kernel/call_stack.rb
facets-1.3.1 lib/facets/core/kernel/call_stack.rb
facets-1.4.0 lib/facets/core/kernel/call_stack.rb
facets-1.4.2 lib/facets/core/kernel/call_stack.rb
facets-1.4.1 lib/facets/core/kernel/call_stack.rb
facets-1.4.3 lib/facets/core/kernel/call_stack.rb
facets-1.4.4 lib/facets/core/kernel/call_stack.rb
facets-1.4.5 lib/facets/core/kernel/call_stack.rb
facets-1.7.30 lib/facets/core/kernel/call_stack.rb
facets-1.7.38 lib/facets/core/kernel/call_stack.rb
facets-1.7.0 lib/facets/core/kernel/call_stack.rb
facets-1.7.46 lib/facets/core/kernel/call_stack.rb