るりまサーチ

最速Rubyリファレンスマニュアル検索!
55件ヒット [1-55件を表示] (0.072秒)
トップページ > クエリ:-[x] > クエリ:$1[x] > クエリ:caller[x]

別のキーワード

  1. mkmf $cflags
  2. mkmf $libs
  3. mkmf $libdir
  4. kernel $nr
  5. kernel $1

種類

ライブラリ

モジュール

検索結果

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

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

...情報を $@
の形式のバックトレース(文字列の配列)として返します。

トップレベルでは空の配列を返します。caller の戻り値を $@ に代入することで
例外の発生位置を設定できます。

引数で指定した値が範囲外の場合は nil を...
...el.#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>'"]
# ["-:10:in `bar'", "-:13:in `<main>'"]
# ["-: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 (18305.0)

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

...情報を $@
の形式のバックトレース(文字列の配列)として返します。

トップレベルでは空の配列を返します。caller の戻り値を $@ に代入することで
例外の発生位置を設定できます。

引数で指定した値が範囲外の場合は nil を...
...el.#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>'"]
# ["-:10:in `bar'", "-:13:in `<main>'"]
# ["-: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, length) -> [String] | nil (18305.0)

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

...情報を $@
の形式のバックトレース(文字列の配列)として返します。

トップレベルでは空の配列を返します。caller の戻り値を $@ に代入することで
例外の発生位置を設定できます。

引数で指定した値が範囲外の場合は nil を...
...el.#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>'"]
# ["-:10:in `bar'", "-:13:in `<main>'"]
# ["-: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...

Ruby用語集 (144.0)

Ruby用語集 A B C D E F G I J M N O R S Y

...l#percent

: 0 オリジン
: zero-based
番号が 0 から始まること。

例えば、
Array や Vector、Matrix などの要素の番号、
String における文字の位置、
といったものは 0 オリジンである。

: 1 オリジン
: one-based
番号が 1 から始ま...
...おいて、そこに至るメソッド呼び出し元情報を遡るデータ。
バックトレースともいう。

Kernel.#caller_locations、Kernel.#caller で現時点までの
スタックトレースを得ることができる。

また、例外オブジェクトは例外が発生...
...プトのファイル名)は
グローバルスコープであり、どのスレッドから参照しても同じ値であるのに
対し、
$1
(正規表現検索における 1 番目のキャプチャー文字列)はスレッドローカル
であり、スレッドごとに別で...

クラス/メソッドの定義 (114.0)

クラス/メソッドの定義 * クラス/メソッドの定義: * class * singleton_class * module * method * operator * nest_method * eval_method * singleton_method * class_method * limit * 定義に関する操作: * alias * undef * defined

...い場合は nil を返します。

===[a:method] メソッド定義

//emlist[例][ruby]{
def fact(n)
if n == 1 then
1
else
n * fact(n-1)
end
end
//}

文法:

def メソッド名 ['(' [arg0 ['=' default0]] ... [',' '*' rest_args [, post ...]] [',' key1: [val1]] ... [',' '*...
...def foo
p caller.last
end
protected :foo
end

obj = Foo.new

# そのままでは呼べない
obj.foo rescue nil # => -:11 - protected method `foo' called for #<Foo:0x401a1860> (NameError)

# クラス定義内でも呼べない
class Foo
Foo.new.foo rescue nil # => -:15 - protected me...
...$_] # => [2, 2]

$bar = 3
alias $foo $bar
$bar = 4
p [$foo, $bar] # => [4, 4]
//}

ただし、正規表現の部分文字列に対応する変数 $1,$2, ... には別名を付けることができません。
また、インタプリタに対して重要な意味のあるグローバル変数
(d...

絞り込み条件を変える