#### class Array def sieve (*how) call = block_given? slots = Hash[] how.push(Proc.new { true }) how.each { |h| slots[h] = [] } self.each { |x| i = (call == true) ? yield(x) : x how.each { |h| if h.call(i) == true slots[h].push(x) break end } } return how.collect { |h| slots[h] }.flatten end end a = [6,5,2,4,3,1,7] puts a.sieve( Proc.new { |n| n < 5 }, Proc.new { |n| n < 10 } ) { |x| x * 2 }.inspect #### sieve {block 1}.{block 2}.{block 3}.sift(array) {how} #### this_sieve = sieve {b1}.{b2}.{b3} # and then this_sieve.sift(array) { how }