るりまサーチ

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

別のキーワード

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

ライブラリ

キーワード

検索結果

MatchData#captures -> [String] (9126.0)

$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 (6108.0)

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

...の名前付きキャプチャを Hash で返します。

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

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

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

# 名前付きキャプチャが定義されていなかった場合は空のハッシュを返す
m = /(\d{2}):(\d{2}):(\d{2})/.match("18:37:22")
m.deconstruct_keys(nil) # => {}
//}

@see d:spec/pattern_matching#matching_non_primitive_objects...

MatchData#deconstruct -> [String] (6026.0)

$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...