In some strange behavior, and wonders if anyone else can confirm what I see.
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 be changing the value of @val, although I only granted it read privileges.
test = TestClass.new('hello')
puts test.val
test.val << ' world'
puts test.val
It returns
hello
hello world
This is just the result of some testing that I did in irb, so I'm not sure if this is always the case.
Robin source
share