On 2014-06-28 14:20, Ary Borenszweig wrote:
In Ruby the usage of a variable is always prefixed: `@foo` for instance
vars, `$foo` for global variable, `FOO` for constant. You can't make a
mistake. It's... perfect :-)
Oh, that's where you're wrong, very wrong :). Take this for example:
class Foo
attr_accessor :bar
def initialize
@bar = 3
end
def foo
puts bar # prints "bar", the instance variable, via a getter
bar = 4
puts bar # prints "bar", the local variable
puts self.bar # prints "bar", the instance variable, via a getter
end
end
Foo.new.foo
--
/Jacob Carlborg