Ruby クラスを作成していて、== メソッドをオーバーライドしたいと考えています。私は次のようなことを言いたいです:
class ReminderTimingInfo
attr_reader :times, :frequencies #don't want these to exist
def initialize(times, frequencies)
@times, @frequencies = times, frequencies
end
...
def ==(other)
@times == other.times and @frequencies == other.frequencies
end
end
時間と頻度の両方を公開せずにこれを行うにはどうすればよいですか?
ファローアップ:
class ReminderTimingInfo
def initialize(times, frequencies)
@date_times, @frequencies = times, frequencies
end
...
def ==(other)
@date_times == other.times and @frequencies == other.frequencies
end
protected
attr_reader :date_times, :frequencies
end