0

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?

1
  • if it an array my not use .uniq! Commented Oct 29, 2012 at 15:01

2 Answers 2

4
@ads = @ads.uniq

or

@ads.uniq!
Sign up to request clarification or add additional context in comments.

Comments

4

The below code will give you the result uniqic by id.

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

2 Comments

It accepts a block? You really learn every day on this site :)
@SergioTulentsev guess it started in 1.9

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.