From: walter a kehowski Date: 2005-08-08T08:31:09+09:00 Subject: Re: cartesian product Hello, If one defines class Array def cartprod(b) each do |ae| b.each do |be| if block_given? yield ae, be else (c ||= []) << [ae, be] end end end c end end then a=[[1,2,3],[4,5,6],[7,8,9]] c=cartpord(a.slice(0..-1)) c.each {|ce| ce.each {|x| print x," " }; print "\n" } gives the error cartprod.rb:45: undefined method `cartpord' for main:Object (NoMethodError) and a=[[1,2,3],[4,5,6],[7,8,9]] c=a[0] b=a.slice(1..-1) b.each{|be| c=c.cartprod(be) } c.each {|ce| ce.each {|x| print x," " }; print "\n" } gives the error cartprod.rb:24:in `cartprod': undefined local variable or method `c' for [1, 2, 3]:Array (NameError) from cartprod.rb:49 from cartprod.rb:49:in `each' from C:/Documents and Settings/walter/My Documents/cartprod.rb:49 and, finally, a=[[1,2,3],[4,5,6],[7,8,9]] c=cartprod(a) c.each {|ce| ce.each {|x| print x," " }; print "\n" } gives the error cartprod.rb:45: undefined method `cartprod' for main:Object (NoMethodError) Well, I'm clearly plying around trying to get it JUST RIGHT. Walter Kehowski