From: Phrogz Date: 2008-02-14T08:10:30+09:00 Subject: Re: my noob "numbering lines" programe. How to improve? On Feb 13, 3:50 pm, Adam Akhtar wrote: > Give us hints on how to improve this program. If you want to show your > code off then go ahead but please give us the hints first i.e. what > methods you would use, what you would rewrite in my code etc. Its so > much better for me to go away and try and replicate your thinking than > just reading it. Here are some suggestions: * Use the += and *= compound assignment operators * Use << instead of .write * "%10s" % str is like rjust, so * "%#{numdigits}s %s" % [ linenumber, input ] * Look at each_with_index * Think about a better way to calculate numdigits; e.g.: * Math.log10( max ).ceil * total_lines.to_s.size