From: Robert Klemme Date: 2008-05-30T05:20:00+09:00 Subject: Re: Merge collections of objects On 29.05.2008 20:03, John Butler wrote: > Robert Klemme wrote: >> 2008/5/29 John Butler : >>> Copy any employees from companyB that are not in companyA >>> passing through the 2 objects and the relationship in dyn_method: >>> dyn_method = 'company_employees' >>> companyA.send(dyn_method + '=',companyB.send(dyn_method)) >>> > > Thats pretty nice, as you say the struct is pretty similar to the hash > so multiple keys can be checked for duplicates. This is how i have it > working now but i may change to your solution above. My solution doesnt > feel the most effecient. > > for obj in company_b.send(dyn_method) > if !company_a.send(dyn_method).detect { |t| t.id == obj.id} > company_a.send(dyn_method) << obj > end > end Efficiency large depends on the sizes of collections involved. Your approach can actually be faster for smaller sets. You have to measure it. Kind regards robert