From ae2cc6463a1299acae06ddf8573ef996b0ae58bd Mon Sep 17 00:00:00 2001 From: Casey Dahlin Date: Fri, 3 Oct 2008 17:13:39 -0400 Subject: Add implementation of product Ruby 1.8.6 doesn't have Array#product, so add it --- state.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/state.rb b/state.rb index 011567b..b69421a 100644 --- a/state.rb +++ b/state.rb @@ -5,6 +5,17 @@ Author: Casey Dahlin =end require 'set' +unless Array.instance_methods.include? "product" + class Array #:nodoc: + def product(*others) + return self.map{ |x| [x] } if others.size == 0 + self.map do |x| + (others[0].product(*others[1..-1])).map{ |y| [x] + y } + end.inject([]){ |x,y| x+y } + end + end +end + module UpState # Occurs when the state machine becomes inconsistent -- cgit