2件ヒット
[1-2件を表示]
(0.284秒)
検索結果
-
Struct
# hash -> Integer (42352.0) -
self が保持するメンバのハッシュ値を元にして算出した整数を返します。 self が保持するメンバの値が変化すればこのメソッドが返す値も変化します。
...も変化します。
//emlist[例][ruby]{
Dog = Struct.new(:name, :age)
dog = Dog.new("fred", 5)
p dog.hash #=> 7917421
dog.name = "john"
p dog.hash #=> -38913223
//}
[注意] 本メソッドの記述は Struct の下位クラスのインスタンスに対し......て呼び
出す事を想定しています。Struct.new は Struct の下位クラスを作成する点に
注意してください。... -
Struct
# to _ h -> Hash (24364.0) -
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}
//}
[注意] 本メソッドの記述は Struct の下位クラスのインスタンス......に対して呼び
出す事を想定しています。Struct.new は Struct の下位クラスを作成する点に
注意してください。...