るりまサーチ

最速Rubyリファレンスマニュアル検索!
11件ヒット [1-11件を表示] (0.280秒)
トップページ > クエリ:b[x] > クエリ:_builtin[x] > クエリ:trace[x] > 種類:クラス[x]

別のキーワード

  1. _builtin new
  2. _builtin inspect
  3. _builtin []
  4. _builtin to_s
  5. _builtin each

ライブラリ

検索結果

Thread::Backtrace::Location (14019.0)

Ruby のフレームを表すクラスです。

...Ruby のフレームを表すクラスです。

Kernel.#caller_locations から生成されます。

//emlist[例1][ruby]{
# caller_locations.rb
def a(skip)
caller_locations(skip)
end
def b(skip)
a(skip)
end
def c(skip)
b
(skip)
end

c(0..2).map do |call|
puts call.to_s
end
//}

例1の実...
...行結果:

caller_locations.rb:2:in `a'
caller_locations.rb:5:in `b'
caller_locations.rb:8:in `c'

//emlist[例2][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|
puts call.to...
..._s
end
//}

例2の実行結果:

init.rb:4:in `initialize'
init.rb:8:in `new'
init.rb:8:in `<main>'

=== 参考

* Ruby VM アドベントカレンダー #4 vm_backtrace.c: https://www.atdot.net/~ko1/diary/201212.html#d4...