summaryrefslogtreecommitdiffstats
path: root/state.rb
diff options
context:
space:
mode:
authorCasey Dahlin <cdahlin@redhat.com>2008-10-03 17:13:39 -0400
committerCasey Dahlin <cdahlin@redhat.com>2008-10-03 17:13:39 -0400
commitae2cc6463a1299acae06ddf8573ef996b0ae58bd (patch)
tree5cb1fd33263fb1a633a89fe9ccf2b37c0a093515 /state.rb
parent41aa7774fa4cf587dc985ac99a0f8c1c3dd163c6 (diff)
downloadupstate-ae2cc6463a1299acae06ddf8573ef996b0ae58bd.tar.gz
upstate-ae2cc6463a1299acae06ddf8573ef996b0ae58bd.tar.xz
upstate-ae2cc6463a1299acae06ddf8573ef996b0ae58bd.zip
Add implementation of product
Ruby 1.8.6 doesn't have Array#product, so add it
Diffstat (limited to 'state.rb')
-rw-r--r--state.rb11
1 files changed, 11 insertions, 0 deletions
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 <cjdahlin@ncsu.edu>
=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