diff options
| author | Casey Dahlin <cdahlin@redhat.com> | 2008-10-03 17:13:39 -0400 |
|---|---|---|
| committer | Casey Dahlin <cdahlin@redhat.com> | 2008-10-03 17:13:39 -0400 |
| commit | ae2cc6463a1299acae06ddf8573ef996b0ae58bd (patch) | |
| tree | 5cb1fd33263fb1a633a89fe9ccf2b37c0a093515 | |
| parent | 41aa7774fa4cf587dc985ac99a0f8c1c3dd163c6 (diff) | |
| download | upstate-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
| -rw-r--r-- | state.rb | 11 |
1 files changed, 11 insertions, 0 deletions
@@ -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 |
