Skip to content

Instantly share code, notes, and snippets.

@cutthroat
Created October 26, 2010 20:58
Show Gist options
  • Save cutthroat/647786 to your computer and use it in GitHub Desktop.
Save cutthroat/647786 to your computer and use it in GitHub Desktop.
cartesian product of array valued hash
def product(h)
k = h.keys
v = h.values_at(*k)
p = v.shift.product(*v)
p.map { |v| Hash[k.zip(v)] }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment