An example will explain the question:
Val = Struct.new(:value) do
def inc
p value
value = value + 1
end
end
v = Val.new(1)
v.inc
The output will be:
1
undefined method `+' for nil:NilClass (NoMethodError)
Why do I get this error when value
is clearly not nil? Is there a way to make this work?