When I call first_array | second_arrayon two arrays containing user objects:
first_array = [co1, co2, co3]
second_array =[co2, co3, co4]
he returns [co1, co2, co3, co2, co3, co4]. It does not remove duplicates. I tried to call uniqthe result, but it did not work either. What should I do?
Update:
This is a custom object:
class Task
attr_accessor :status, :description, :priority, :tags
def initiate_task task_line
@status = task_line.split("|")[0]
@description = task_line.split("|")[1]
@priority = task_line.split("|")[2]
@tags = task_line.split("|")[3].split(",")
return self
end
def <=>(another_task)
stat_comp = (@status == another_task.status)
desc_comp = (@description == another_task.description)
prio_comp = (@priority == another_task.priority)
tags_comp = (@tags == another_task.tags)
if(stat_comp&desc_comp&prio_comp&tags_comp) then return 0 end
end
end
and when I create several instances of type Task and drop them into two different arrays, and when I try to call '|' nothing happens on them, it simply returns an array that includes both the first and second elements of the array without deleting duplicates.
source
share