Ruby/Array/reject

Материал из Wiki.crossplatform.ru

Перейти к: навигация, поиск

reject the even ones

primes = [2,3,5,7]
primes.reject {|x| x%2==0}  # => [3,5,7]: reject the even ones



reject with block logic

a = ["a", "b", "c", "d", "e", "f", "g", "h"]
p a.reject { |x| x < "e" }         # => ["e", "f", "g", "h"]