我试图找出一种方法来迭代并从四个不同的来源中删除重复记录。
first_source = [#<Customer:0x007f911e307ad0 @id="123", @name="Whitehall">,# <Customer:0x007f911e307ad0 @id="124", @name="Whitehall">#<Customer:0x007f911e307ad0 @id="125", @name="Whitehall">]
second_source = [#<Customer:0x007f911e307ad0 @id="5000", @name="Whitehall">,#<Customer:0x007f911e307ad0 @id="5500", @name="Whitehall">#<Customer:0x007f911e307ad0 @id="123", @name="Whitehall">]
third_source = [#<Customer:0x007f911e307ad0 @id="800", @name="Whitehall">,#<Customer:0x007f911e307ad0 @id="5000", @name="Whitehall">#<Customer:0x007f911e307ad0 @id="124", @name="Whitehall">]
fourth_source = [#<Customer:0x007f911e307ad0 @id="4300", @name="Whitehall">,#<Customer:0x007f911e307ad0 @id="800", @name="Whitehall">#<Customer:0x007f911e307ad0 @id="125", @name="Whitehall">]
我试过
customers = []
dup_customers = first_source + second_source + third_source + fourth_source
dup_customers.combination(2).each do |cs1, cs2|
customers << cs1 unless cs1.id != cs2.id
end
但这确实行不通。
有人可以帮我建议一种方法/策略来遍历这四个集合并找到相等的客户 ID,然后用它做点什么吗?