简体   繁体   中英

Loop through array and delete all duplicates in ruby

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 = @ads.uniq

要么

@ads.uniq!

下面的代码将通过id给您唯一的结果。

@ads = @ads.uniq{|ad| ad.id}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM