From: Andrew Wagner Date: 2010-10-06T04:34:34+09:00 Subject: Re: Calling a method with an instance --005045017bd30dff350491e3c0bb Content-Type: text/plain; charset=UTF-8 Um, I think you guys mean Discount.discount_amount(dis1.amount,dis1.discount) discount_amount is not an instance method. Or am I missing something? On Tue, Oct 5, 2010 at 3:25 PM, Jedrin wrote: > 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) > > --005045017bd30dff350491e3c0bb--