From: Colin Bartlett Date: 2010-05-10T05:01:01+09:00 Subject: Re: Strings iteration On Sun, May 9, 2010 at 5:26 PM, Rick DeNatale wrote: >>> >> On 08.05.2010 12:12, Viorel wrote: >>> >>> I have some names like aaxxbbyy where xx is '01'..'10' and yy is also >>> >>> '01'..'10'. I think there is a simple, rubyst way of iterating through >>> >>> them, and I ask for your help in finding it. Thank you in advance! > >> The difference is that I have to iterate through yy for a given xx. >> xx='01', yy='01'..'10', so I have 100 outputs, not only 10. > > (1..10).each do |x| >  (1..10).each do |y| >    puts "aa%02dyy%02d" % [ x, y] >  end > end I'm reminded of this Ruby-Talk post! http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/95623 Subject: Re: How to pass a given block to a subroutine From: Simon Strandgaard Date: Tue, 23 Mar 2004 23:44:37 +0900 References: 95616 95617 On Tue, 23 Mar 2004 23:37:14 +0900, ts wrote: > "L" == Lothar Scholz writes: > L> def foo (*args) > def foo(*args, &block) > L> subroutine *args > subroutine(*args, &block) > L> end > Guy Decoux Im too slow.. Decoux you are too fast.. ;-) ***** I'd remembered that Simon Strandgaard was replying to Guy Decoux, but I'd forgotten that the original question was from Lothar Scholz, so it's nice that three people of whom I have fond ruby-talk memories were involved in that exchange. (And I wish I'd paid more attention at the time to what was being said in that thread about passing blocks as Proc object arguments to methods: if I had, I would have had a much cleaner version of something I was trying to do about two years ago, instead of making the cleaner version only this year!) That said, using the ranges of the original question in this thread, something like this also seems to work if the ranges for both xx and yy are the same. (If they aren't, use a separate range for yy.) xx = "09" .. "10" # using "09" instead of "00" to reduce the output xx.each do |x| xx.each do |y| puts "aa" + x + "bb" + y end end #=> aa09bb09 aa09bb10 aa10bb09 aa10bb10