Add cartesian to Enumerable : Enumerable « Collections « Ruby

Add cartesian to Enumerable

module Enumerable
  def cartesian(other)
    inject([]) { |res, x| other.inject(res) { |res, y| res << [x,y] } }


Related examples in the same category

1.get Enumerable involved
2.Sorting an Array by Frequency of Appearance
3.Building a Histogram
4.Call each a number of times
5.randomly each
6.Writing Block Methods that Classify or Collect
7.Implementing Enumerable - Write One Method, Get 22 Free
9.Sort on two arrays