hello,
i have a question according 'self'. I have setup a small simple scenario
to simulate the problem.

This following small program works fine ..

> class User
>   def set_foo
>     self.x = '1'
>   end
>   def get_foo
>     x
>   end
>   def x=(val)
>     @x = val
>   end
>   def x
>     @x
>   end
> end
> 
> u = User.new
> u.set_foo
> puts(u.x)
> puts(u.get_foo)

when i now remove the 'self' within the method 'set_foo' it does not set
the values any more.

> class User
>   def set_foo
>     x = '1'
>   end
>   def get_foo
>     x
>   end
>   def x=(val)
>     @x = val
>   end
>   def x
>     @x
>   end
> end
> 
> u = User.new
> u.set_foo
> puts(u.x)
> puts(u.get_foo)

so my 1st question is: why doesnt the 'set_foo' method calls the 'x'
method if i remove the self?
THE INTERESTING THING: 'get_foo' works with 'x' and 'self.x'

and the 2nd question: when should i use self now and when not and why is
there this strange behavoir?

thanks for looking into this.
-- 
Posted via http://www.ruby-forum.com/.