From: John Barnette Date: 2009-06-18T01:28:24+09:00 Subject: Re: private method - Fixnum (NoMethodError) Hi, On Wed, Jun 17, 2009 at 9:13 AM, salai wrote: > I can't find the error in my code. Can you explain me "private method > -  Fixnum (NoMethodError)"? > > def subtotal(qty = 1) >        return nil if self.to_f <= 0 || qty.to_f <= 0 >        self.to_f * qty.to_f > end > > apple = 11 > > puts apple.subtotal(2) You've defined the 'subtotal' method in the global scope, which is equivalent to defining a private instance method on Object. Private methods can't be called with a receiver. If you really want to do this (this method seems bizarre to me), you'll want to reopen one or more of the numeric classes and define your method there, e.g., class Fixnum def subtotal qty = 1 return nil if to_f <= 0 || qty.to_f <= 0 to_f * qty.to_f end end apple = 11 puts apple.subtotal(2) # 22.0 ~ j.