method
reject
![Wide documentation Importance_3](https://d2vfyqvduarcvs.cloudfront.net/images/importance_3.png?1349367920)
reject()
public
Returns a new array containing the items in self for which the given block is not true. The ordering of non-rejected elements is maintained.
See also Array#delete_if
If no block is given, an Enumerator is returned instead.
Register or
log in
to add new notes.
Mange -
February 16, 2009
ronald -
March 26, 2009
![Default_avatar_30](https://www.gravatar.com/avatar/1b2792536d87aa21bc739c14980fa103?default=http://apidock.com/images/default_avatar_30.png&size=30)
6 thanks
Usage example
Some examples:
# Remove even numbers (1..30).reject { |n| n % 2 == 0 } # => [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29] # Remove years dividable with 4 (this is *not* the full leap years rule) (1950..2000).reject { |y| y % 4 != 0 } # => [1952, 1956, 1960, 1964, 1968, 1972, 1976, 1980, 1984, 1988, 1992, 1996, 2000] # Remove users with karma below arithmetic mean total = users.inject(0) { |total, user| total += user.karma } mean = total / users.size good_users = users.reject { |u| u.karma < mean }
![Default_avatar_30](https://www.gravatar.com/avatar/83da11bf035086a765af8d2e5777e954?default=http://apidock.com/images/default_avatar_30.png&size=30)
1 thank