Ran into some weird behaviour and wondering if anyone else can confirm what I am seeing.
Suppose you create a class with a member variable, and allow it to be read with attr_reader.
class TestClass
attr_reader :val
def initialize(value)
@val = value
end
end
Now when I do the following, it seems to modify the value of @val, even though I have only granted it read privileges.
test = TestClass.new('hello')
puts test.val
test.val << ' world'
puts test.val
This returns
hello
hello world
This is just the result from some testing I did in irb so not sure if this is always the case
attr_readermeans that you can't set the value, i.e., no methodvalue=is defined. It certainly doesn't mean that you can't cal a method on the object