別のキーワード
種類
- インスタンスメソッド (48)
- 文書 (36)
キーワード
- captures (2)
- deconstruct (14)
-
deconstruct
_ keys (20) -
to
_ a (6) - values (6)
- オブジェクト指向スクリプト言語 Ruby リファレンスマニュアル (12)
- パターンマッチ (12)
- 制御構造 (12)
検索結果
先頭5件
-
パターンマッチ (23000.0)
-
パターンマッチ * patterns * variable_binding * variable_pinning * matching_non_primitive_objects * guard_clauses * current_feature_status * pattern_syntax * some_undefined_behavior_examples
パターンマッチ
* patterns
* variable_binding
* variable_pinning
* matching_non_primitive_objects
* guard_clauses
* current_feature_status
* pattern_syntax
* some_undefined_behavior_examples
パターンマッチは、構造化された値に対して、構造をチェックし、マッチした部分をローカル変数に束縛するという、深いマッチを可能にする実験的な機能です。(『束縛』は、パターンマッチの輸入元である関数型言語...パターンマッチ
* patterns
* variable_binding
* variable_pinning
* matching_non_primitive_objects
* guard_clauses
* current_feature_status
* pattern_syntax
* some_undefined_behavior_examples
パターンマッチは、構造化された値に対して、構造をチェックし、マッチした部分をローカル変数に束縛するという、深いマッチを可能にする機能です。(『束縛』は、パターンマッチの輸入元である関数型言語の用語で... -
CSV
:: Row # deconstruct -> [object] (6.0) -
パターンマッチに使用する行の値の配列を返します。
...3])
case row
in [2.., 2.., 2..]
puts "all 2 or more"
in [...2, 2.., 2..]
puts "first column is less than 2, and rest columns are 2 or more"
end
#=> "first column is less than 2, and rest columns are 2 or more" が出力される
//}
@see d:spec/pattern_matching#matching_non_primitive_objects... -
CSV
:: Row # deconstruct _ keys(keys) -> Hash (6.0) -
パターンマッチに使用するヘッダの名前と値の Hash を返します。
.... }
puts "all 2 or more"
in { header1: ...2, header2: 2.., header3: 2.. }
puts "first column is less than 2, and rest columns are 2 or more"
end
#=> "first column is less than 2, and rest columns are 2 or more" が出力される
//}
@see d:spec/pattern_matching#matching_non_primitive_objects... -
Data
# deconstruct -> [object] (6.0) -
self のメンバの値を配列で返します。
......
end
//}
[注意] 本メソッドの記述は Data のサブクラスのインスタンスに対して呼び
出す事を想定しています。Data.define は Data のサブクラスを作成する点に
注意してください。
@see d:spec/pattern_matching#matching_non_primitive_objects... -
Data
# deconstruct _ keys(array _ of _ names _ or _ nil) -> Hash (6.0) -
self のメンバの名前と値の組を Hash で返します。
...ます。
[注意] 本メソッドの記述は Data のサブクラスのインスタンスに対して呼び
出す事を想定しています。Data.define は Data のサブクラスを作成する点に
注意してください。
@see d:spec/pattern_matching#matching_non_primitive_objects... -
Date
# deconstruct _ keys(array _ of _ names _ or _ nil) -> Hash (6.0) -
パターンマッチに使用する名前と値の Hash を返します。
...g day in month #{month}"
end
#=> "working day in month 10" が出力される
# クラスのチェックと組み合わせて利用することもできます
if d in Date(wday: 3, day: ..7)
puts "first Wednesday of the month"
end
//}
@see d:spec/pattern_matching#matching_non_primitive_objects... -
DateTime
# deconstruct _ keys(array _ of _ names _ or _ nil) -> Hash (6.0) -
パターンマッチに使用する名前と値の Hash を返します。
...> "working day in month 10" が出力される
# クラスのチェックと組み合わせて利用することもできます
if dt in DateTime(wday: 1..5, hour: 10..18, day: ..7)
puts "Working time, first week of the month"
end
//}
@see d:spec/pattern_matching#matching_non_primitive_objects... -
MatchData
# captures -> [String] (6.0) -
$1, $2, ... を格納した配列を返します。
...応する要素は 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] (6.0) -
$1, $2, ... を格納した配列を返します。
...応する要素は 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 (6.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... -
Struct
# deconstruct -> [object] (6.0) -
構造体のメンバの値を配列にいれて返します。
...345]
//}
[注意] 本メソッドの記述は Struct の下位クラスのインスタンスに対して呼び
出す事を想定しています。Struct.new は Struct の下位クラスを作成する点に
注意してください。
@see d:spec/pattern_matching#matching_non_primitive_objects... -
Struct
# deconstruct _ keys(array _ of _ names) -> Hash (6.0) -
self のメンバの名前と値の組を Hash で返します。
...345}
//}
[注意] 本メソッドの記述は Struct の下位クラスのインスタンスに対して呼び
出す事を想定しています。Struct.new は Struct の下位クラスを作成する点に
注意してください。
@see d:spec/pattern_matching#matching_non_primitive_objects... -
Struct
# to _ a -> [object] (6.0) -
構造体のメンバの値を配列にいれて返します。
...345]
//}
[注意] 本メソッドの記述は Struct の下位クラスのインスタンスに対して呼び
出す事を想定しています。Struct.new は Struct の下位クラスを作成する点に
注意してください。
@see d:spec/pattern_matching#matching_non_primitive_objects... -
Struct
# values -> [object] (6.0) -
構造体のメンバの値を配列にいれて返します。
...345]
//}
[注意] 本メソッドの記述は Struct の下位クラスのインスタンスに対して呼び
出す事を想定しています。Struct.new は Struct の下位クラスを作成する点に
注意してください。
@see d:spec/pattern_matching#matching_non_primitive_objects... -
Time
# deconstruct _ keys(array _ of _ names _ or _ nil) -> Hash (6.0) -
パターンマッチに使用する名前と値の Hash を返します。
...ng day in month #{month}"
end
#=> "working day in month 10" が出力される
# クラスのチェックと組み合わせて利用することもできます
if t in Time(wday: 3, day: ..7)
puts "first Wednesday of the month"
end
//}
@see d:spec/pattern_matching#matching_non_primitive_objects... -
オブジェクト指向スクリプト言語 Ruby リファレンスマニュアル (6.0)
-
オブジェクト指向スクリプト言語 Ruby リファレンスマニュアル * Ruby オフィシャルサイト https://www.ruby-lang.org/ja/ * version 2.4 対応リファレンス * 原著:まつもとゆきひろ * 最新版URL: https://www.ruby-lang.org/ja/documentation/
...:
* spec/lexical
* spec/program
* spec/variables
* spec/literal
* spec/operator
* spec/control
* spec/call
* spec/def
* spec/pattern_matching
その他:
* spec/m17n
* spec/regexp
* spec/lambda_proc
==== 組み込みライブラリ
* _builtin
==== 標準添付ライブラ... -
制御構造 (6.0)
-
制御構造 条件分岐: * if * unless * case 繰り返し: * while * until * for * break * next * redo * retry 例外処理: * raise * begin その他: * return * BEGIN * END
...b: 2, c: 3}
in a: Integer => m
"matched: #{m}"
else
"not matched"
end
# => "matched: 1"
//}
パターンマッチ構文についてはspec/pattern_matchingで説明しています。
=== 繰り返し
====[a:while] while
//emlist[例][ruby]{
ary = [0,2,4,8,16,32,64,128,256,512,1024]
i = 0
wh...