require 'set'
class Array
def classify
h = {}
each do |i|
x = yield(i)
(h[x] ||= self.class.new) << i
end
h
end
def divide(&block)
Set.new(classify(&block).values)
end
end
p [1,1,2,6,6,7,101].divide { |x| x % 2 }
# => #