method
uniq
![Moderate documentation Importance_2](https://d2vfyqvduarcvs.cloudfront.net/images/importance_2.png?1349367920)
uniq()
public
Register or
log in
to add new notes.
bvida -
January 25, 2010
Vidmantas -
January 14, 2013 - (>= v1_8_6_287)
![Default_avatar_30](https://www.gravatar.com/avatar/ad8a7e0887893372f12943eb49bfcbff?default=http://apidock.com/images/default_avatar_30.png&size=30)
2 thanks
![Default_avatar_30](https://www.gravatar.com/avatar/6c85cc2920423530609e7d80d6b2d17f?default=http://apidock.com/images/default_avatar_30.png&size=30)
0 thanks
Pass a block
While this example is not so obvious on first look what the block passed does, here’s a small explanation:
when the block is passed to this function, the uniqueness is checked based on a value returned by that block.
For example if it’s array of objects with “user_id” method, then this would be:
tasks.uniq{|t| t.user_id } # returns only tasks with unique user_id