From: Mike Harris Date: 2006-06-27T01:13:49+09:00 Subject: Re: Some ugly code (again) arnaud stageman wrote: >Hello! > >I have (again) some ruby code to beautifulize :-) > >I have 2 Range {1..x} and {1..y} and a name >My goal is to have formatted names like : name + y + x > >For example: >rack11 rack12 rack13 >rack21 rack22 rack23 > >Can I do nicer than: > >{1..y}.each do |y| > {1..x}.each do |x| > the_name = name + y.to_s + x.to_s > end >end > >??? > > >Arnaud. > > > The cartesian_product method doesn't exist, you would have to write it. It's trivial (1..y).cartesian_product((1..x)).map { |x| name + x.join("") }