るりまサーチ

最速Rubyリファレンスマニュアル検索!
12件ヒット [1-12件を表示] (0.107秒)

別のキーワード

  1. _builtin deconstruct_keys
  2. _builtin deconstruct
  3. struct deconstruct_keys
  4. struct deconstruct
  5. date deconstruct_keys

ライブラリ

クラス

検索結果

Data#deconstruct_keys(array_of_names_or_nil) -> Hash (18132.0)

self のメンバの名前と値の組を Hash で返します。

...

//emlist[例][ruby]{
Measure = Data.define(:amount, :unit)

distance = Measure.new(10, 'km')
distance.deconstruct_keys(nil) # => {:amount=>10, :unit=>"km"}
distance.deconstruct_keys([:amount]) # => {:amount=>10}
//}

このメソッドは以下のようにパターンマッチで利用さ...
...#deconstruct_keys を呼ぶ
puts "It is #{amount} kilometers away"
else
puts "Don't know how to handle it"
end

# "It is 10 kilometers away" が表示される

# 以下のようにも書ける
case distance
in Measure(amount:, unit: 'km')
puts "It is #{amount} kilometers away"
# ...
end

//}...

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

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

...3, day: ..7 # deconstruct_keys が使われます
puts "first Wednesday 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...

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

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

...in wday: 1..5, hour: 10..18 # deconstruct_keys が使われます
puts "Working time"
end

#=> "Working time" が出力される

case dt
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 1...
...0" が出力される

# クラスのチェックと組み合わせて利用することもできます
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...

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

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

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

CSV::Row#deconstruct_keys(keys) -> Hash (18108.0)

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

...: 2.. }
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_objec...

絞り込み条件を変える