나는 네 가지 소스에서 중복 레코드를 반복하고 제거하는 방법을 알아 내려고하고 있습니다. 별도의 배열에 두 개 이상의 개체 속성 비교
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
을 시도하지만이 정말 작동하지 않았다.
누군가이 4 가지 컬렉션을 탐색하고 동일한 ID를 가진 고객 ID를 찾는 방법을 제안 할 수 있습니까?
중복이있는 경우, 당신은/모든 소스, 또는 모든 하나, 또는 없음을 제외한 모두에서 제거 하시겠습니까? 중복을 제거하는 대신 검색을 원한다는 의미입니까? – sawa
또한, 두 개의 Customer 객체가 동일한'id' 속성을 가지고 있다면 중복 객체라고 생각하십니까? – pje