From: Dick Davies Date: 2010-08-23T15:19:59+09:00 Subject: Re: convert 125% into 1.25? Ah, good catch both, thanks. On Mon, Aug 23, 2010 at 2:02 AM, Rob Biedenharn wrote: > On Aug 22, 2010, at 7:59 PM, Ryan Davis wrote: >> >> On Aug 22, 2010, at 13:32 , Dick Davies wrote: >> >>> ?> class Fixnum >>>>> >>>>> def percent >> >> the appropriate place to put that is Integer, not Fixnum. >> >>> % ruby -e 'p 100.class.superclass' >>> Integer > > Or even Numeric: > > irb> 1.class.ancestors > => [Fixnum, Integer, Numeric, Comparable, Object, Kernel, BasicObject] > irb> class Numeric > irb>   def percent > irb>     self.to_f / 100.0 > irb>     end > irb>   end > => nil > irb> 5.percent > => 0.05 > irb> 125.percent > => 1.25 > irb> 14.7.percent > => 0.147 > irb> (99+"44/100".to_r).percent > => 0.9944