検索結果
先頭5件
-
Kernel
$ $ 3 -> String | nil (15207.0) -
最後に成功したパターンマッチで n 番目の括弧にマッチした値が格納されます。 該当する括弧がなければ nil が入っています。(覚え方: \数字 のようなもの)
...最後に成功したパターンマッチで n 番目の括弧にマッチした値が格納されます。
該当する括弧がなければ nil が入っています。(覚え方: \数字 のようなもの)
番号 n はいくらでも大きな正整数を利用できます。
Regexp.last_matc......れらの変数はローカルスコープかつスレッドローカル、読み取り専用です。
//emlist[例][ruby]{
str = '<p><a href="http://example.com">example.com</a></p>'
if %r[<a href="(.*?)">(.*?)</a>] =~ str
print $1
print $2
end
#=> "http://example.com"
#=> "example.com"
//}... -
変数と定数 (3222.0)
-
変数と定数 * local * instance * class * class_var_scope * global * pseudo * const * prio
...変数と定数
* local
* instance
* class
* class_var_scope
* global
* pseudo
* const
* prio
Ruby の変数と定数の種別は変数名の最初の一文字によって、
ローカル変数、
インスタンス変数、
クラス変数、
グローバル変数、
定数
のい......ます。初期化されていない
インスタンス変数を参照した時の値はnilです。
===[a:class] クラス変数
//emlist[例][ruby]{
class Foo
@@foo = 1
def bar
puts @@foo
end
end
//}
@@で始まる変数はクラス変数です。クラス変数はクラス定義
の......$1, $2, $3 がそうです。
このように 「'$' + 特殊文字一文字」、または「'$' + 10進数字」という名前を持つ変数を特殊変数と呼びます。
また、 $-F や $-I のような変数もあります。
これらは Ruby の起動オプションと -F や -I など... -
Kernel
. # caller(range) -> [String] | nil (154.0) -
start 段上の呼び出し元の情報を $@ の形式のバックトレース(文字列の配列)として返します。
...caller の戻り値を $@ に代入することで
例外の発生位置を設定できます。
引数で指定した値が範囲外の場合は nil を返します。
@param start long の範囲を超えない正の整数でスタックレベルを指定します。
@param length 取得するス......ernel.#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>'"]
#......nil
//}
以下の関数は、caller の要素から [ファイル名, 行番号, メソッド名]
を取り出して返します。
//emlist[例][ruby]{
def parse_caller(at)
if /^(.+?):(\d+)(?::in `(.*)')?/ =~ at
file = $1
line = $2.to_i
method = $3
[file, line, method]
end
end... -
Kernel
. # caller(start = 1) -> [String] | nil (154.0) -
start 段上の呼び出し元の情報を $@ の形式のバックトレース(文字列の配列)として返します。
...caller の戻り値を $@ に代入することで
例外の発生位置を設定できます。
引数で指定した値が範囲外の場合は nil を返します。
@param start long の範囲を超えない正の整数でスタックレベルを指定します。
@param length 取得するス......ernel.#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>'"]
#......nil
//}
以下の関数は、caller の要素から [ファイル名, 行番号, メソッド名]
を取り出して返します。
//emlist[例][ruby]{
def parse_caller(at)
if /^(.+?):(\d+)(?::in `(.*)')?/ =~ at
file = $1
line = $2.to_i
method = $3
[file, line, method]
end
end... -
Kernel
. # caller(start , length) -> [String] | nil (154.0) -
start 段上の呼び出し元の情報を $@ の形式のバックトレース(文字列の配列)として返します。
...caller の戻り値を $@ に代入することで
例外の発生位置を設定できます。
引数で指定した値が範囲外の場合は nil を返します。
@param start long の範囲を超えない正の整数でスタックレベルを指定します。
@param length 取得するス......ernel.#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>'"]
#......nil
//}
以下の関数は、caller の要素から [ファイル名, 行番号, メソッド名]
を取り出して返します。
//emlist[例][ruby]{
def parse_caller(at)
if /^(.+?):(\d+)(?::in `(.*)')?/ =~ at
file = $1
line = $2.to_i
method = $3
[file, line, method]
end
end... -
Kernel
$ $ 1 -> String | nil (107.0) -
最後に成功したパターンマッチで n 番目の括弧にマッチした値が格納されます。 該当する括弧がなければ nil が入っています。(覚え方: \数字 のようなもの)
...最後に成功したパターンマッチで n 番目の括弧にマッチした値が格納されます。
該当する括弧がなければ nil が入っています。(覚え方: \数字 のようなもの)
番号 n はいくらでも大きな正整数を利用できます。
Regexp.last_matc......れらの変数はローカルスコープかつスレッドローカル、読み取り専用です。
//emlist[例][ruby]{
str = '<p><a href="http://example.com">example.com</a></p>'
if %r[<a href="(.*?)">(.*?)</a>] =~ str
print $1
print $2
end
#=> "http://example.com"
#=> "example.com"
//}... -
Kernel
$ $ 10 -> String | nil (107.0) -
最後に成功したパターンマッチで n 番目の括弧にマッチした値が格納されます。 該当する括弧がなければ nil が入っています。(覚え方: \数字 のようなもの)
...最後に成功したパターンマッチで n 番目の括弧にマッチした値が格納されます。
該当する括弧がなければ nil が入っています。(覚え方: \数字 のようなもの)
番号 n はいくらでも大きな正整数を利用できます。
Regexp.last_matc......れらの変数はローカルスコープかつスレッドローカル、読み取り専用です。
//emlist[例][ruby]{
str = '<p><a href="http://example.com">example.com</a></p>'
if %r[<a href="(.*?)">(.*?)</a>] =~ str
print $1
print $2
end
#=> "http://example.com"
#=> "example.com"
//}... -
Kernel
$ $ 11 -> String | nil (107.0) -
最後に成功したパターンマッチで n 番目の括弧にマッチした値が格納されます。 該当する括弧がなければ nil が入っています。(覚え方: \数字 のようなもの)
...最後に成功したパターンマッチで n 番目の括弧にマッチした値が格納されます。
該当する括弧がなければ nil が入っています。(覚え方: \数字 のようなもの)
番号 n はいくらでも大きな正整数を利用できます。
Regexp.last_matc......れらの変数はローカルスコープかつスレッドローカル、読み取り専用です。
//emlist[例][ruby]{
str = '<p><a href="http://example.com">example.com</a></p>'
if %r[<a href="(.*?)">(.*?)</a>] =~ str
print $1
print $2
end
#=> "http://example.com"
#=> "example.com"
//}... -
Kernel
$ $ 2 -> String | nil (107.0) -
最後に成功したパターンマッチで n 番目の括弧にマッチした値が格納されます。 該当する括弧がなければ nil が入っています。(覚え方: \数字 のようなもの)
...最後に成功したパターンマッチで n 番目の括弧にマッチした値が格納されます。
該当する括弧がなければ nil が入っています。(覚え方: \数字 のようなもの)
番号 n はいくらでも大きな正整数を利用できます。
Regexp.last_matc......れらの変数はローカルスコープかつスレッドローカル、読み取り専用です。
//emlist[例][ruby]{
str = '<p><a href="http://example.com">example.com</a></p>'
if %r[<a href="(.*?)">(.*?)</a>] =~ str
print $1
print $2
end
#=> "http://example.com"
#=> "example.com"
//}... -
Kernel
$ $ 4 -> String | nil (107.0) -
最後に成功したパターンマッチで n 番目の括弧にマッチした値が格納されます。 該当する括弧がなければ nil が入っています。(覚え方: \数字 のようなもの)
...最後に成功したパターンマッチで n 番目の括弧にマッチした値が格納されます。
該当する括弧がなければ nil が入っています。(覚え方: \数字 のようなもの)
番号 n はいくらでも大きな正整数を利用できます。
Regexp.last_matc......れらの変数はローカルスコープかつスレッドローカル、読み取り専用です。
//emlist[例][ruby]{
str = '<p><a href="http://example.com">example.com</a></p>'
if %r[<a href="(.*?)">(.*?)</a>] =~ str
print $1
print $2
end
#=> "http://example.com"
#=> "example.com"
//}...