Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class CartesianProduct
- include Enumerable
- @@p
- def initialize(arg1, arg2)
- @@p = arg1.product arg2
- end
- def each
- @@p.each do |elt| yield elt end
- end
- end
- #Examples of use
- c = CartesianProduct.new([:a,:b], [4,5])
- c.each { |elt| puts elt.inspect }
- # [:a, 4]
- # [:a, 5]
- # [:b, 4]
- # [:b, 5]
- c = CartesianProduct.new([:a,:b], [])
- c.each { |elt| puts elt.inspect }
- # (nothing printed since Cartesian product
- # of anything with an empty collection is empty)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement