I don't understand why I get a nil error. I created the setter properly. But it does not accept -=, +=, or itself behind the = operator. Why?
class Test
def var; @var || 0; end
def var=(value)
@var = value
end
def initialize
@var = 2.4 # Sample value
end
def test
puts var
var -= 1 # <<< crash: undefined method for nil class
puts var
var = var - 1 # <<< crash: undefined method for nil class
puts var
end
end
a = Test.new
a.test