種類
- インスタンスメソッド (8)
- 文書 (3)
ライブラリ
- ビルトイン (8)
クラス
- MatchData (8)
キーワード
- captures (2)
-
deconstruct
_ keys (2) -
named
_ captures (2) - パターンマッチ (3)
検索結果
先頭5件
-
MatchData
# deconstruct -> [String] (24119.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 (15119.0) -
引数で指定された名前の名前付きキャプチャを Hash で返します。
...。
//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
# captures -> [String] (9019.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
# named _ captures -> Hash (9018.0) -
名前付きキャプチャをHashで返します。
..."a" => "0", "b" => "1"}
m = /(?<a>.)(?<b>.)?/.match("0")
m.named_captures # => {"a" => "0", "b" => nil}
m = /(?<a>.)(?<a>.)/.match("01")
m.named_captures # => {"a" => "1"}
m = /(?<a>x)|(?<a>y)/.match("x")
m.named_captures # => {"a" => "x"}
//}
@see MatchData#captures, MatchData#deconstruct_keys... -
MatchData
# named _ captures(symbolize _ names: false) -> Hash (9018.0) -
名前付きキャプチャをHashで返します。
...", "b" => nil}
m = /(?<a>.)(?<a>.)/.match("01")
m.named_captures # => {"a" => "1"}
m = /(?<a>x)|(?<a>y)/.match("x")
m.named_captures # => {"a" => "x"}
m = /(?<a>.)(?<a>.)/.match("01")
m.named_captures(symbolize_names: true) #=> {:a => "1"}
//}
@see MatchData#captures, MatchData#deconstruct_keys... -
パターンマッチ (156.0)
-
パターンマッチ * patterns * variable_binding * variable_pinning * matching_non_primitive_objects * guard_clauses * current_feature_status * pattern_syntax * some_undefined_behavior_examples
...ることができます。
Array パターン と Find パターン は配列か deconstruct メソッド(後述)を持つオブジェクトにマッチします。
Hash パターン はハッシュか deconstruct_keys メソッド(後述)を持つオブジェクトにマッチします。Hash......ブジェクトのマッチ: deconstruct メソッドと deconstruct_keys メソッド
既に述べたように、Array/Find/Hash パターンは、配列やハッシュのリテラルの他に、deconstruct メソッド(Array/Find パターン) あるいは deconstruct_keys メソッド(Hash パ......"not matched"
end
#=> "matched: 1"
//}
以下のクラスは deconstruct や deconstruct_keys を実装しています。
MatchData#deconstruct
MatchData#deconstruct_keys
Time#deconstruct_keys
Date#deconstruct_keys
DateTime#deconstruct_keys
===[a:guard_clauses] ガード節
if を使って、...