4件ヒット
[1-4件を表示]
(0.023秒)
別のキーワード
検索結果
先頭4件
-
Data
# deconstruct _ keys(array _ of _ names _ or _ nil) -> Hash (54358.0) -
self のメンバの名前と値の組を Hash で返します。
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}
//}
このメソッドは以下のようにパターンマッチで利用されます。
//emlist[例][ruby]... -
Struct
# deconstruct _ keys(array _ of _ names) -> Hash (54340.0) -
self のメンバの名前と値の組を Hash で返します。
self のメンバの名前と値の組を Hash で返します。
@param array_of_names 返り値に含めるメンバの名前の配列を指定します。nil の場合は全てのメンバを意味します。
//emlist[例][ruby]{
Customer = Struct.new(:name, :address, :zip)
joe = Customer.new("Joe Smith", "123 Maple, Anytown NC", 12345)
h = joe.deconstruct_keys([:zip, :address])
h # => {:zip=>12345, :address... -
CSV
:: Row # deconstruct _ keys(keys) -> Hash (54304.0) -
パターンマッチに使用するヘッダの名前と値の Hash を返します。
パターンマッチに使用するヘッダの名前と値の Hash を返します。
このメソッドはヘッダ名の型をシンボルに変換しないため、ヘッダ名が文字列かつ Hash パターン でパターンマッチしたい場合はキーをシンボルに変換する必要があります。
@param keys パターンマッチに使用するヘッダの名前の配列を指定します。nil の場合は全てをパターンマッチに使用します。
//emlist[例][ruby]{
require "csv"
row = CSV::Row.new([:header1, :header2, :header3], [1, 2, 3])
case row
in { hea... -
パターンマッチ (253.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
パターンマッチは、構造化された値に対して、構造をチェックし、マッチした部分をローカル変数に束縛するという、深いマッチを可能にする機能です。(『束縛』は、パターンマッチの輸入元である関数型言語の用語で...