From: Jedrin Date: 2010-10-06T04:25:12+09:00 Subject: Re: Calling a method with an instance On Oct 5, 3:20 pm, Jedrin wrote: > On Oct 5, 2:59 pm, Paul Roche wrote: > > > > > Hi. I'm playing around with creating methods and then creating an > > instance that calls the instance. Here's my code..... > > > class Discount > > attr_accessor :amount, :discount > > >  def initialize(am, dis) > > @amount = am > > @discount = dis > > > end > > > def self.discount_amount(amt, disc) > > newamount = amt - disc > > end > > > end > > > dis1 = Discount.new(100, 20) > > > dis1.discount_amount(amount, discount) > > > The error I get is...... > > > discount.rb:25:in `
': undefined local variable or method `amount' > > for main > > :Object (NameError) > > > What is the best way to call a method with an instance? > > Thanks > > -- > > Posted viahttp://www.ruby-forum.com/. > > I think u want: > dis1.discount_amount(dis1.amount, discount) this works, but not sure if this approach is most sensible dis1.discount_amount(dis1.amount, dis1.discount)