るりまサーチ

最速Rubyリファレンスマニュアル検索!
88件ヒット [1-88件を表示] (0.079秒)
トップページ > ライブラリ:ビルトイン[x] > クエリ:p[x] > クエリ:caller_locations[x]

別のキーワード

  1. kernel caller
  2. _builtin caller
  3. kernel caller_locations
  4. _builtin caller_locations
  5. caller _builtin

モジュール

キーワード

検索結果

Kernel.#caller_locations(range) -> [Thread::Backtrace::Location] | nil (18134.0)

現在のフレームを Thread::Backtrace::Location の配列で返します。引 数で指定した値が範囲外の場合は nil を返します。

...。引
数で指定した値が範囲外の場合は nil を返します。

@param start 開始フレームの位置を数値で指定します。

@param length 取得するフレームの個数を指定します。

@param range 取得したいフレームの範囲を示す Range オブジェク...
...f test1(start, length)
locations = caller_locations(start, length)
p
locations
p
locations.map(&:lineno)
p
locations.map(&:path)
end

def test2(start, length)
test1(start, length)
end

def test3(start, length)
test2(start, length)
end

caller_locations
# => []
test3(1, nil)
# => ["/Users...

Kernel.#caller_locations(start = 1, length = nil) -> [Thread::Backtrace::Location] | nil (18134.0)

現在のフレームを Thread::Backtrace::Location の配列で返します。引 数で指定した値が範囲外の場合は nil を返します。

...。引
数で指定した値が範囲外の場合は nil を返します。

@param start 開始フレームの位置を数値で指定します。

@param length 取得するフレームの個数を指定します。

@param range 取得したいフレームの範囲を示す Range オブジェク...
...f test1(start, length)
locations = caller_locations(start, length)
p
locations
p
locations.map(&:lineno)
p
locations.map(&:path)
end

def test2(start, length)
test1(start, length)
end

def test3(start, length)
test2(start, length)
end

caller_locations
# => []
test3(1, nil)
# => ["/Users...

Thread::Backtrace::Location#absolute_path -> String (6108.0)

self が表すフレームの絶対パスを返します。

...][ruby]{
# foo.rb
class Foo
attr_accessor :locations
def initialize(skip)
@locations = caller_locations(skip)
end
end

Foo.new(0..2).locations.map do |call|
p
uts call.absolute_path
end

# => /path/to/foo.rb
# /path/to/foo.rb
# /path/to/foo.rb
//}

@see Thread::Backtrace::Location#path...

Thread::Backtrace::Location#inspect -> String (6108.0)

Thread::Backtrace::Location#to_s の結果を人間が読みやすいような文 字列に変換したオブジェクトを返します。

...][ruby]{
# foo.rb
class Foo
attr_accessor :locations
def initialize(skip)
@locations = caller_locations(skip)
end
end

Foo.new(0..2).locations.map do |call|
p
uts call.inspect
end

# => "path/to/foo.rb:5:in `initialize'"
# "path/to/foo.rb:9:in `new'"
# "path/to/foo.rb:9:in `<main>'"
//}...

Thread::Backtrace::Location#path -> String (6108.0)

self が表すフレームのファイル名を返します。

...self が表すフレームのファイル名を返します。

例: Thread::Backtrace::Location の例1を用いた例

//emlist[][ruby]{
loc = c(0..1).first
loc.path # => "caller_locations.rb"
//}

@see Thread::Backtrace::Location#absolute_path...

絞り込み条件を変える

Kernel.#caller(range) -> [String] | nil (62.0)

start 段上の呼び出し元の情報を $@ の形式のバックトレース(文字列の配列)として返します。

...指定した値が範囲外の場合は nil を返します。

@param start long の範囲を超えない正の整数でスタックレベルを指定します。
@param length 取得するスタックの個数を指定します。

@param range 取得したいスタックの範囲を示す Range...
...オブジェクトを指定します。

@see Kernel.#set_trace_func,Kernel.#raise,
Kernel.#caller_locations

//emlist[例][ruby]{
def foo
p
caller(0)
p
caller(1)
p
caller(2)
p
caller(3)
p
caller(4)
end

def bar
foo
end

bar

#=> ["-:2:in `foo'", "-:10:in `bar'", "-:13:in `<main>'"]...
...//emlist[例][ruby]{
def parse_caller(at)
if /^(.+?):(\d+)(?::in `(.*)')?/ =~ at
file = $1
line = $2.to_i
method = $3
[file, line, method]
end
end

def foo
p
parse_caller(caller.first)
end

def bar
foo
p
parse_caller(caller.first)
end

bar
p
parse_caller(caller.first)

#=...

Kernel.#caller(start = 1) -> [String] | nil (62.0)

start 段上の呼び出し元の情報を $@ の形式のバックトレース(文字列の配列)として返します。

...指定した値が範囲外の場合は nil を返します。

@param start long の範囲を超えない正の整数でスタックレベルを指定します。
@param length 取得するスタックの個数を指定します。

@param range 取得したいスタックの範囲を示す Range...
...オブジェクトを指定します。

@see Kernel.#set_trace_func,Kernel.#raise,
Kernel.#caller_locations

//emlist[例][ruby]{
def foo
p
caller(0)
p
caller(1)
p
caller(2)
p
caller(3)
p
caller(4)
end

def bar
foo
end

bar

#=> ["-:2:in `foo'", "-:10:in `bar'", "-:13:in `<main>'"]...
...//emlist[例][ruby]{
def parse_caller(at)
if /^(.+?):(\d+)(?::in `(.*)')?/ =~ at
file = $1
line = $2.to_i
method = $3
[file, line, method]
end
end

def foo
p
parse_caller(caller.first)
end

def bar
foo
p
parse_caller(caller.first)
end

bar
p
parse_caller(caller.first)

#=...

Kernel.#caller(start, length) -> [String] | nil (62.0)

start 段上の呼び出し元の情報を $@ の形式のバックトレース(文字列の配列)として返します。

...指定した値が範囲外の場合は nil を返します。

@param start long の範囲を超えない正の整数でスタックレベルを指定します。
@param length 取得するスタックの個数を指定します。

@param range 取得したいスタックの範囲を示す Range...
...オブジェクトを指定します。

@see Kernel.#set_trace_func,Kernel.#raise,
Kernel.#caller_locations

//emlist[例][ruby]{
def foo
p
caller(0)
p
caller(1)
p
caller(2)
p
caller(3)
p
caller(4)
end

def bar
foo
end

bar

#=> ["-:2:in `foo'", "-:10:in `bar'", "-:13:in `<main>'"]...
...//emlist[例][ruby]{
def parse_caller(at)
if /^(.+?):(\d+)(?::in `(.*)')?/ =~ at
file = $1
line = $2.to_i
method = $3
[file, line, method]
end
end

def foo
p
parse_caller(caller.first)
end

def bar
foo
p
parse_caller(caller.first)
end

bar
p
parse_caller(caller.first)

#=...