るりまサーチ

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

別のキーワード

  1. rbconfig ruby
  2. fiddle ruby_free
  3. fiddle build_ruby_platform
  4. rake ruby
  5. rubygems/defaults ruby_engine

ライブラリ

クラス

検索結果

Data#deconstruct -> [object] (18138.0)

self のメンバの値を配列で返します。

...列で返します。

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

distance = Measure.new(10, 'km')
distance.deconstruct # => [10, "km"]
//}

このメソッドは以下のようにパターンマッチで利用されます。

//emlist[例][ruby]{
Measure = Data.define(:amount, :uni...
...'km' # 裏側で #deconstruct を呼ぶ
puts "It is #{n} kilometers away"
else
puts "Don't know how to handle it"
end

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

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

//}

[注意]...

CSV::Row#deconstruct -> [object] (18114.0)

パターンマッチに使用する行の値の配列を返します。

...を返します。

//emlist[例][ruby]{
require "csv"
row = CSV::Row.new(["header1", "header2", "header3"], [1, 2, 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, an...

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

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

...の名前と値の組を 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}
//}

このメソッドは以下...
...れます。

//emlist[例][ruby]{
Measure = Data.define(:amount, :unit)
distance = Measure.new(10, 'km')

case distance
in amount:, unit: 'km' # 裏側で #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

//}

@param array_of_names_or_nil 返り値に含めるメンバの名前の配列を指定します。nil の場合は全てのメンバを意味し...

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

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

...l の場合は全てをパターンマッチに使用します。

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

if d in wday: 3, day: ..7 # deconstruct_keys が使われます
puts "first Wednesday of the month"
end

#=> "first Wednesday of the month" が出力される

case d
in year: ...2022...
...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_n...

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

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

...場合は全てをパターンマッチに使用します。

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

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

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

case dt
in year: ...2022
puts "too old...
...working day in month #{month}"
end

#=> "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_matc...

絞り込み条件を変える

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

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

...合は全てをパターンマッチに使用します。

//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: ...2...
...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_n...

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

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

...st[例][ruby]{
require "csv"

row = CSV::Row.new([:header1, :header2, :header3], [1, 2, 3])
case row
in { header1: 2.., header2: 2.., header3: 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

#=> "f...