Given I've got an array arr of instances of a custom class My_class. This class has got a couple of different instance variables. Let's call them :name (a String), :is_processed (a Boolean) and :date (a DateTime). All of them are readable.
What is the best way of checking, whether another given instance of My_class (call it newbe) is already in the array based on the content of the aforementioned instance variables?
Using arr.include?(newbe) will not work as this compares the object IDs, doesn't it?
Can I override the way Array#include? compares two objects?
Speaking in code
class My_class
attr_reader :name, :is_processed, :date
def initialize(_name, _proc, _d)
@name = _name
@is_processed = _proc
@date = _d
end
end
somewhere else
first = My_class.new("First", false, DateTime.new(2001,2,3,4,5,6))
second = My_class.new("Second", true, DateTime.new(2001,2,3,4,5,6))
third = My_class.new("Third", false, DateTime.new(2001,2,3,3,2,1))
newbe = My_class.new("Second", true, DateTime.new(2001,2,3,4,5,6))
arr = [first, second, third]
arr.include?(newbe) # => false but should be true