1件ヒット
[1-1件を表示]
(0.137秒)
ライブラリ
- ビルトイン (1)
検索結果
-
Struct
# to _ h {|member , value| block } -> Hash (18607.0) -
self のメンバ名(Symbol)と値の組を Hash にして返します。
...self のメンバ名(Symbol)と値の組を Hash にして返します。
//emlist[例][ruby]{
Customer = Struct.new(:name, :address, :zip)
Customer.new("Joe Smith", "123 Maple, Anytown NC", 12345).to_h
# => {:name=>"Joe Smith", :address=>"123 Maple, Anytown NC", :zip=>12345}
//}
ブロックを......omer = Struct.new(:name, :address, :zip)
Customer.new("Joe Smith", "123 Maple, Anytown NC", 12345).to_h {|member, value|
[member, value*2]
} # => {:name=>"Joe SmithJoe Smith", :address=>"123 Maple, Anytown NC123 Maple, Anytown NC", :zip=>24690}
//}
[注意] 本メソッドの記述は Struct の......下位クラスのインスタンスに対して呼び
出す事を想定しています。Struct.new は Struct の下位クラスを作成する点に
注意してください。...