On Fri, May 25, 2012 at 12:14 PM, Robinson Risquez <lists / ruby-forum.com>wrote:

>
> Certainly can be done in many ways, but what I want to do is spend just
> an attribute as a parameter to a method of the form: object.attribute,
> then you can modify this attribute in the method, as follows:
>
>  def adder (attribute)
>   attribute + = 1
>  end
>
>  That's what I do, but can not find the way.
>

then may be this is better ....

class SomeClass
  attr_accessor :attribute

  def initialize(attribute)
    @attribute = attribute
  end

  def adder(attribute)
    self.attribute += 1
  end
end

val = SomeClass.new(5)

k=0
while (k<10) do
  puts val.adder(:attribute)
  k+=1
end

  without the 'self', ruby interprets "attribute" to be a local variable!

saji

-- 

Saji N Hameed,
ARC-ENV, Center for Advanced Information Science and Technology,
University of Aizu, Tsuruga, Ikki-machi,
Aizuwakamatsu-shi, Fukushima 965-8580,
Japan

Tel: +81242 37-2736
Fax:+81242 37-2760
 email: saji / u-aizu.ac.jp
 url: http://www.u-aizu.ac.jp
 bib: http://www.researcherid.com/rid/B-9188-2009