るりまサーチ

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

別のキーワード

  1. fiddle ref
  2. entity ref
  3. pointer ref
  4. _builtin _id2ref
  5. rexml/document ref

ライブラリ

キーワード

検索結果

MatchData#captures -> [String] (7.0)

$1, $2, ... を格納した配列を返します。

...$1, $2, ... を格納した配列を返します。

MatchData
#to_a と異なり $& を要素に含みません。
グループにマッチした部分文字列がなければ対応する要素は nil になります。

//emlist[例][ruby]{
/(foo)(bar)(BAZ)?/ =~ "foobarbaz"
p $~.to_a # => ["...
...foobar", "foo", "bar", nil]
p $~.captures # => ["foo", "bar", nil]
//}

@see MatchData#to_a, MatchData#named_captures, d:spec/pattern_matching#matching_non_primitive_objects...

MatchData#deconstruct -> [String] (7.0)

$1, $2, ... を格納した配列を返します。

...$1, $2, ... を格納した配列を返します。

MatchData
#to_a と異なり $& を要素に含みません。
グループにマッチした部分文字列がなければ対応する要素は nil になります。

//emlist[例][ruby]{
/(foo)(bar)(BAZ)?/ =~ "foobarbaz"
p $~.to_a # => ["...
...foobar", "foo", "bar", nil]
p $~.captures # => ["foo", "bar", nil]
//}

@see MatchData#to_a, MatchData#named_captures, d:spec/pattern_matching#matching_non_primitive_objects...

MatchData#deconstruct_keys(array_of_names) -> Hash (7.0)

引数で指定された名前の名前付きキャプチャを Hash で返します。

引数で指定された名前の名前付きキャプチャを Hash で返します。

Hash のキーは名前付きキャプチャの名前のシンボル、値はキーの名前に対応した名前付きグループのうち最後にマッチした文字列です。

@param array_of_names 名前付きキャプチャの名前の配列を指定します。nil の場合は全ての名前付きキャプチャを意味します。

//emlist[例][ruby]{
m = /(?<hours>\d{2}):(?<minutes>\d{2}):(?<seconds>\d{2})/.match("18:37:22")
m.deconstruct_keys([:hours, :m...