Ruby 3.0.0 リファレンスマニュアル > ライブラリ一覧 > 組み込みライブラリ > Structクラス > eql?

instance method Struct#eql?

eql?(other) -> bool[permalink][rdoc]

self と other のクラスが同じであり、各メンバが eql? メソッドで比較して等しい場合に true を返します。そうでない場合に false を返します。

[PARAM] other:
self と比較したいオブジェクトを指定します。


Dog = Struct.new(:name, :age)
dog1 = Dog.new("fred", 5)
dog2 = Dog.new("fred", 5)

p dog1 == dog2                #=> true
p dog1.eql?(dog2)             #=> true
p dog1.equal?(dog2)           #=> false

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

[SEE_ALSO] Struct#==