As far as I know, there is no such way in Ruby. I'm sure this is just how Ruby evaluates expressions.
When setting the value, Ruby will first check to see if there is a local variable in the context that matches the called one. If in your case there is (possibly "foo"), this will be the value used. If there is no such value, then Ruby will try to find the value as a method call (switching to "I" as the caller). If such a method does not exist in the search path, an error occurs.
The need to use "self" in setter is to avoid Ruby setting the value as a local variable, while the lack of using "self" only works in the getter instance when there is no local variable of the same name used in this context . It is probably better and clearer, albeit a little more verbose, to be explicit with your use of the ego in order to avoid confusion as to where the values โโcome from.
source share