I need to loop through an array called @ads and delete all objects in it that are duplicates of one another. how do i do this?
我需要遍历一个名为@ads的数组,并删除其中彼此重复的所有对象。我该怎么做呢?
2 个解决方案
#1
4
@ads = @ads.uniq
or
要么
@ads.uniq!
#2
4
The below code will give you the result uniqic by id.
下面的代码将通过id为您提供uniqic的结果。
@ads = @ads.uniq{|ad| ad.id}
#1
4
@ads = @ads.uniq
or
要么
@ads.uniq!
#2
4
The below code will give you the result uniqic by id.
下面的代码将通过id为您提供uniqic的结果。
@ads = @ads.uniq{|ad| ad.id}