From: Daniel Schierbeck Date: 2006-06-26T20:27:47+09:00 Subject: Re: Some ugly code (again) arnaud stageman wrote: > 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 Here's a one-liner for ya: (1..x).map{|x| (1..y).map{|y| "rack#{x}#{y}"}}.flatten Cheers, Daniel