るりまサーチ

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

別のキーワード

  1. _builtin first
  2. array first
  3. matrix first_minor
  4. range first
  5. enumerable first

ライブラリ

クラス

検索結果

Date#deconstruct_keys(array_of_names_or_nil) -> Hash (18232.0)

パターンマッチに使用する名前と値の Hash を返します。

...@param array_of_names_or_nil パターンマッチに使用する名前の配列を指定します。nil の場合は全てをパターンマッチに使用します。

//emlist[例][ruby]{
d = Date.new(2022, 10, 5)

if d in wday: 3, day: ..7 # deconstruct_keys が使われます
puts "first Wedn...
...esday of the month"
end
#=> "first Wednesday of the month" が出力される

case d
in year: ...2022
puts "too old"
in month: ..9
puts "quarter 1-3"
in wday: 1..5, month:
puts "working 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...

Time#deconstruct_keys(array_of_names_or_nil) -> Hash (18232.0)

パターンマッチに使用する名前と値の Hash を返します。

...* :zone

@param array_of_names_or_nil パターンマッチに使用する名前の配列を指定します。nil の場合は全てをパターンマッチに使用します。

//emlist[例][ruby]{
t = Time.utc(2022, 10, 5, 21, 25, 30)

if t in wday: 3, day: ..7 # deconstruct_keys が使われま...
...
puts "first Wednesday of the month"
end
#=> "first Wednesday of the month" が出力される

case t
in year: ...2022
puts "too old"
in month: ..9
puts "quarter 1-3"
in wday: 1..5, month:
puts "working 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...

DateTime#deconstruct_keys(array_of_names_or_nil) -> Hash (18220.0)

パターンマッチに使用する名前と値の Hash を返します。

...zone

@param array_of_names_or_nil パターンマッチに使用する名前の配列を指定します。nil の場合は全てをパターンマッチに使用します。

//emlist[例][ruby]{
dt = DateTime.new(2022, 10, 5, 13, 30)

if dt in wday: 1..5, hour: 10..18 # deconstruct_keys が使わ...
...> "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...

パターンマッチ (192.0)

パターンマッチ * patterns * variable_binding * variable_pinning * matching_non_primitive_objects * guard_clauses * current_feature_status * pattern_syntax * some_undefined_behavior_examples

...ジェクト (when と同じように、『===』演算子でマッチする) (「Value パターン」)
* Array パターン: 『[<subpattern>, <subpattern>, <subpattern>, ...]』 (「Array パターン」)
* Hash パターン: 『{key: <subpattern>, key: <subpattern>, ...}』 (「Hash パタ...
...意のパターンをネストさせることができます。

Array
パターン は配列か deconstruct メソッド(後述)を持つオブジェクトにマッチします。

Hash パターン はハッシュか deconstruct_keys メソッド(後述)を持つオブジェクトにマッチし...
...用できます。

//emlist[][ruby]{
case {name: 'John', friends: [{name: 'Jane'}, {name: 'Rajesh'}]}
in name:, friends: [{name: first_friend}, *]
"matched: #{first_friend}"
else
"not matched"
end
#=> "matched: Jane"
//}

パターンの残りの部分も同様に変数に束縛できます。...
...ジェクト (when と同じように、『===』演算子でマッチする) (「Value パターン」)
* Array パターン: 『[<subpattern>, <subpattern>, <subpattern>, ...]』 (「Array パターン」)
* Find パターン: 『[*variable, <subpattern>, <subpattern>, <subpattern>, ..., *vari...
...ーンをネストさせることができます。

Array
パターン と Find パターン は配列か deconstruct メソッド(後述)を持つオブジェクトにマッチします。

Hash パターン はハッシュか deconstruct_keys メソッド(後述)を持つオブジェクトにマ...