From: Jeremy Bopp Date: 2010-10-06T04:46:50+09:00 Subject: Re: Calling a method with an instance On 10/5/2010 2:32 PM, Paul Roche wrote: > Jedrin wrote: >> On Oct 5, 3:20�pm, Jedrin wrote: >>>> �def initialize(am, dis) >>> >>>> 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) > > Thanks for this. What is the best way to go about dealing with a method > such as this that has two parameters? I think the comment about sensibility regards the passing of an object's internal values to one of the object's own methods. Assuming you redefine the discount_amount method as an instance method, there is no need to pass in these values since they will be available to the method as @amount and @discount: class Discount attr_accessor :amount, :discount def initialize(amount, discount) @amount = amount @discount = discount end # defined discount_amount as an instance method rather than a # class method def discount_amount @amount - @discount end end dis1 = Discount.new(100, 20) dis1.discount_amount # => 80 -Jeremy