From: Jigar Gosar Date: 2008-02-14T19:35:58+09:00 Subject: Re: How can I write this method in one line? Sebastian Hungerecker wrote: > Jigar Gosar wrote: >> def gen_indices_string num >> string = "" >> num.times{|i| string<<(i+1).to_s} >> return string >> end >> >> I have a feeling that stuff can be written in a single line using some >> of the ruby API. Can anyone help? > > (1..num).to_a.join > or > (1..num).inject("") {|str,i| str << i.to_s} thanks, I knew there was a better way :) -- Posted via http://www.ruby-forum.com/.