るりまサーチ

最速Rubyリファレンスマニュアル検索!
6件ヒット [1-6件を表示] (0.126秒)
トップページ > 種類:インスタンスメソッド[x] > クエリ:ruby[x] > クエリ:struct[x] > クラス:Struct[x] > クエリ:deconstruct_keys[x]

別のキーワード

  1. struct new
  2. mkmf have_struct_member
  3. struct each_pair
  4. struct members
  5. kernel have_struct_member

ライブラリ

検索結果

Struct#deconstruct_keys(array_of_names) -> Hash (33245.0)

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

...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=>"123 Maple, Anytown NC"}

# 引数が nil の場合は全てのメンバを返します。
h = joe.deconstruct...
...:address=>"123 Maple, Anytown NC", :zip=>12345}
//}

[注意] 本メソッドの記述は Struct の下位クラスのインスタンスに対して呼び
出す事を想定しています。Struct.new は Struct の下位クラスを作成する点に
注意してください。

@see d:spec/patter...