18件ヒット
[1-18件を表示]
(0.012秒)
ライブラリ
- ビルトイン (18)
キーワード
- captures (2)
- deconstruct (2)
-
deconstruct
_ keys (2) - inspect (12)
検索結果
先頭4件
-
MatchData
# inspect -> String (6101.0) -
self の内容を人間に読みやすい文字列にして返します。
....$/.match("foo").inspect
# => #<MatchData "o">
puts /(.)(.)(.)/.match("foo").inspect
# => #<MatchData "foo" 1:"f" 2:"o" 3:"o">
puts /(.)(.)?(.)/.match("fo").inspect
# => #<MatchData "fo" 1:"f" 2:nil 3:"o">
puts /(?<foo>.)(?<bar>.)(?<baz>.)/.match("hoge").inspect
# => #<MatchData "hog" foo:"h" bar... -
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 で返します。
...{: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...