How come I get the error NoMethodError: undefined method '+' for nil:NilClass
but the line with puts test
prints out a 1 so we know that the value is initialized?
class TestClass
attr_accessor :test
def initialize()
@test = 1
end
def testFn
puts test
test = test + 1
end
end
t = TestClass.new
t.testFn
It also works if I change test
to @test
but I thought I didn't have to if I had attr_accessor :test