select

ary.select { |item| block } â new_ary
ary.select â Enumerator
Instance Public methods

Returns a new array containing all elements of ary for which the given block returns a true value.

If no block is given, an Enumerator is returned instead.

[1,2,3,4,5].select { |num|  num.even?  }   #=> [2, 4]

a = %w{ a b c d e f }
a.select { |v| v =~ /[aeiou]/ }  #=> ["a", "e"]

See also Enumerable#select.

doc_ruby_on_rails
2015-03-30 19:48:45
Comments
Leave a Comment

Please login to continue.