Sha256: 0bec6277ea348f60b462ead72f810f6caae9180bc57839c25b8b74923b498c67

Contents?: true

Size: 966 Bytes

Versions: 8

Compression:

Stored size: 966 Bytes

Contents

#          Copyright (c) 2006 Michael Fellinger m.fellinger@gmail.com
# All files in this distribution are subject to the terms of the Ruby license.

module Ramaze

  # Gives you back the file, line and method of the caller number i
  # Example:
  #   Ramaze.caller_info(1)
  #   # => ['/usr/lib/ruby/1.8/irb/workspace.rb', '52', 'irb_binding']

  def self.caller_info(i = 1)
    file, line, meth = *parse_backtrace(caller[i])
  end

  # Parses one line of backtrace and tries to extract as much information
  # as possible.
  #
  # Example:
  #   line = "/web/repo/ramaze/lib/ramaze/dispatcher.rb:105:in `respond'"
  #   Ramaze.parse_backtrace(line)
  #   #=> ["/web/repo/ramaze/lib/ramaze/dispatcher.rb", "105", "respond"]

  def self.parse_backtrace(line = '')
    full = line.scan(/(.*?):(\d+):in `(.*?)'/).first
    return full if full and full.all?
    partial = line.scan(/(.*?):(\d+)/).first
    return partial if partial and partial.all?
    line
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
ramaze-0.0.9 lib/ramaze/snippets/ramaze/caller_info.rb
ramaze-0.1.3 lib/ramaze/snippets/ramaze/caller_info.rb
ramaze-0.1.4 lib/ramaze/snippets/ramaze/caller_info.rb
ramaze-0.1.2 lib/ramaze/snippets/ramaze/caller_info.rb
ramaze-0.1.0 lib/ramaze/snippets/ramaze/caller_info.rb
ramaze-0.1.1 lib/ramaze/snippets/ramaze/caller_info.rb
ramaze-0.2.1 lib/ramaze/snippets/ramaze/caller_info.rb
ramaze-0.2.0 lib/ramaze/snippets/ramaze/caller_info.rb