我正在编写一个 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