種類
- モジュール関数 (55)
- 文書 (22)
- インスタンスメソッド (22)
ライブラリ
- ビルトイン (77)
クラス
- Thread (22)
モジュール
- Kernel (55)
キーワード
- Ruby用語集 (11)
-
backtrace
_ locations (22) -
caller
_ locations (22) - 制御構造 (11)
検索結果
先頭5件
-
Kernel
. # caller(start , length) -> [String] | nil (18306.0) -
start 段上の呼び出し元の情報を $@ の形式のバックトレース(文字列の配列)として返します。
...す。caller の戻り値を $@ に代入することで
例外の発生位置を設定できます。
引数で指定した値が範囲外の場合は nil を返します。
@param start long の範囲を超えない正の整数でスタックレベルを指定します。
@param length 取得す......ブジェクトを指定します。
@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>'"]
#......caller の要素から [ファイル名, 行番号, メソッド名]
を取り出して返します。
//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(cal... -
Kernel
. # caller(range) -> [String] | nil (18206.0) -
start 段上の呼び出し元の情報を $@ の形式のバックトレース(文字列の配列)として返します。
...す。caller の戻り値を $@ に代入することで
例外の発生位置を設定できます。
引数で指定した値が範囲外の場合は nil を返します。
@param start long の範囲を超えない正の整数でスタックレベルを指定します。
@param length 取得す......ブジェクトを指定します。
@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>'"]
#......caller の要素から [ファイル名, 行番号, メソッド名]
を取り出して返します。
//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(cal... -
Kernel
. # caller(start = 1) -> [String] | nil (18206.0) -
start 段上の呼び出し元の情報を $@ の形式のバックトレース(文字列の配列)として返します。
...す。caller の戻り値を $@ に代入することで
例外の発生位置を設定できます。
引数で指定した値が範囲外の場合は nil を返します。
@param start long の範囲を超えない正の整数でスタックレベルを指定します。
@param length 取得す......ブジェクトを指定します。
@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>'"]
#......caller の要素から [ファイル名, 行番号, メソッド名]
を取り出して返します。
//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(cal... -
Kernel
. # caller _ locations(start = 1 , length = nil) -> [Thread :: Backtrace :: Location] | nil (6263.0) -
現在のフレームを Thread::Backtrace::Location の配列で返します。引 数で指定した値が範囲外の場合は nil を返します。
...します。
@param length 取得するフレームの個数を指定します。
@param range 取得したいフレームの範囲を示す Range オブジェクトを指定します。
//emlist[例][ruby]{
def 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/user/test.rb:9:in `test2'", "/Users/user/test.rb:13:in `test3'", "/Users/user/test.rb......(1, 2)
# => ["/Users/user/test.rb:9:in `test2'", "/Users/user/test.rb:13:in `test3'"]
# => [9, 13]
# => ["/Users/user/test.rb", "/Users/user/test.rb"]
test3(2, 1)
# => ["/Users/user/test.rb:13:in `test3'"]
# => [13]
# => ["/Users/user/test.rb"]
//}
@see Thread::Backtrace::Location, Kernel.#caller... -
Kernel
. # caller _ locations(range) -> [Thread :: Backtrace :: Location] | nil (6163.0) -
現在のフレームを Thread::Backtrace::Location の配列で返します。引 数で指定した値が範囲外の場合は nil を返します。
...します。
@param length 取得するフレームの個数を指定します。
@param range 取得したいフレームの範囲を示す Range オブジェクトを指定します。
//emlist[例][ruby]{
def 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/user/test.rb:9:in `test2'", "/Users/user/test.rb:13:in `test3'", "/Users/user/test.rb......(1, 2)
# => ["/Users/user/test.rb:9:in `test2'", "/Users/user/test.rb:13:in `test3'"]
# => [9, 13]
# => ["/Users/user/test.rb", "/Users/user/test.rb"]
test3(2, 1)
# => ["/Users/user/test.rb:13:in `test3'"]
# => [13]
# => ["/Users/user/test.rb"]
//}
@see Thread::Backtrace::Location, Kernel.#caller... -
Thread
# backtrace _ locations(start = 0 , length = nil) -> [Thread :: Backtrace :: Location] | nil (113.0) -
スレッドの現在のバックトレースを Thread::Backtrace::Location の配 列で返します。
...レームの位置を数値で指定します。
@param length 取得するフレームの個数を指定します。
@param range 取得したいフレームの範囲を示す Range オブジェクトを指定します。
Kernel.#caller_locations と似ていますが、本メソッドは self... -
Ruby用語集 (18.0)
-
Ruby用語集 A B C D E F G I J M N O R S Y
...である。
「[*0..9]」におけるいわゆる splat 展開の * や、
Proc オブジェクトをブロックとして渡す「strs.map(&:length)」に
おける & も演算子である。
defined? のように、見た目がメソッドのような演算子もある。
参照:spec......おいて、そこに至るメソッド呼び出し元情報を遡るデータ。
バックトレースともいう。
Kernel.#caller_locations、Kernel.#caller で現時点までの
スタックトレースを得ることができる。
また、例外オブジェクトは例外が発生... -
Thread
# backtrace _ locations(range) -> [Thread :: Backtrace :: Location] | nil (13.0) -
スレッドの現在のバックトレースを Thread::Backtrace::Location の配 列で返します。
...レームの位置を数値で指定します。
@param length 取得するフレームの個数を指定します。
@param range 取得したいフレームの範囲を示す Range オブジェクトを指定します。
Kernel.#caller_locations と似ていますが、本メソッドは self... -
制御構造 (12.0)
-
制御構造 条件分岐: * if * unless * case 繰り返し: * while * until * for * break * next * redo * retry 例外処理: * raise * begin その他: * return * BEGIN * END
...nil を返します。
=== 繰り返し
====[a:while] while
//emlist[例][ruby]{
ary = [0,2,4,8,16,32,64,128,256,512,1024]
i = 0
while i < ary.length
print ary[i]
i += 1
end
//}
文法:
while 式 [do]
...
end
式を評価した値が真の間、本体を......で指定された例外を、第二引数をメッセージとして発生さ
せます。第四の形式の第三引数は
$@または
Kernel.#callerで得られる
スタック情報で、例外が発生した場所を示します。
発生した例外は後述の begin 式の rescue 節で捕...