From: Bill Guindon Date: 2005-03-23T06:33:09+09:00 Subject: Re: Any guides for good coding in Ruby? On Wed, 23 Mar 2005 06:09:50 +0900, Arfin wrote: > Is there some kind of class to format numbers? Something to let you > transform: > > 1 => "0001" > 1234 => "1,234.00" > > I needed to display the day and month in a 00 format and the way I did > it was adding a method to the Integer class > > class Integer > def addZero > return "0" + self.to_s if self.to_s.length == 1 > return self.to_s > end > end > t = Time.now > p "The date is: #{t.year}#{t.month.addZero}#{t.day.addZero}" > > What do you guys think of this solution? Might be easier with "printf" - although if you're not familiar with it, might take a bit of work to get the format right. > On a side note, could you guys give a few rules of thumb you follow in > order to make your code clean and readable? Some helpful stuff here: http://www.caliban.org/ruby/rubyguide.shtml Happy Rubying -- Bill Guindon (aka aGorilla)