Created
July 17, 2013 14:10
-
-
Save Papillard/6020874 to your computer and use it in GitHub Desktop.
yielding cartesian product elements..
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CartesianProduct | |
include Enumerable | |
def initialize a,b | |
@a,@b = a,b | |
end | |
def each | |
@a.each do |a_element| | |
@b.each do |b_element| | |
yield [a_element,b_element] | |
end | |
end | |
end | |
end | |
c = CartesianProduct.new([1, 2],[:hehe, :tareum, 6]) | |
c.each {|el| p el} | |
c = CartesianProduct.new([:a,:b], []) | |
c.each {|el| p el} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment