Skip to content

Instantly share code, notes, and snippets.

@vjdhama
Created August 7, 2013 20:30
Show Gist options
  • Save vjdhama/6178318 to your computer and use it in GitHub Desktop.
Save vjdhama/6178318 to your computer and use it in GitHub Desktop.
Edx Class 169.1x HW 1-7
#!/usr/bin/env ruby
class CartesianProduct
include Enumerable
def initialize(array_a, array_b)
@cartesian_array = Array.new(0)
array_a.each do |element_a|
array_b.each do |element_b|
tmp_array = Array.new(0)
tmp_array.push(element_a,element_b)
@cartesian_array.push(tmp_array)
end
end
@cartesian_array
end
def each
@cartesian_array.each { |index| yield(index) }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment