Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 6th, 2012  |  syntax: None  |  size: 0.21 KB  |  hits: 12  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. collection = [4, 3, 2, 6, 4]
  2.  
  3. def filter(collection, &predicate)
  4.   result = []
  5.   collection.each do |t|
  6.     result << t if predicate.call(t)
  7.   end
  8.  
  9.   result
  10. end
  11.  
  12. puts filter(collection) { |x| x % 2 == 0 }