P
Paul Roche
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 `<main>': undefined local variable or method `amount'
for main
:Object (NameError)
What is the best way to call a method with an instance?
Thanks
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 `<main>': undefined local variable or method `amount'
for main
:Object (NameError)
What is the best way to call a method with an instance?
Thanks