--001485f1e9ca1734bb048e7be084 Content-Type: text/plain; charset=ISO-8859-1 On Mon, Aug 23, 2010 at 8:22 AM, Ryan Davis <ryand-ruby / zenspider.com>wrote: > On Aug 22, 2010, at 18:02 , Rob Biedenharn wrote: > > Or even Numeric: > > irb> class Numeric > > irb> def percent > > irb> self.to_f / 100.0 > > irb> end > > irb> end > > ... > I said Integer because of how the original problem was described. I thought > about floats and decided quickly that it didn't make sense... but looking at > your examples above, that actually works and reads pretty well. > As a suggestion, if Rational is being used maybe "override" that with the following to avoid rounding differences: typically interest rates as percentages have the fractional part as 1/2, 3/4, 5/8, etc, so mostly do get "mapped" to "precise" floats, but there might be uses of 2/5, etc class Rational def percent; self / 100; end end class Integer def percent; Rational( self, 100); end end --001485f1e9ca1734bb048e7be084--