I’m using ERB to generate a set of instructions with location data, and want to accept an offset in my input. When I try to check if that offset is present however, it sets it’s value to nil. If anyone can help explain what’s going on it’d be greatly appreciated!
Here’s the code I ran to test this, once I’d narrowed down the problem:
<%
# apply a default value of 0 to the offset hash
p offset.nil?
p offset
p offset.nil?
p offset
if offset.nil?
p "I ran the code inside the if statement"
offset = {}
p "offset has been initialized, since it was nil"
end
p offset.nil?
p offset
%>
and the output:
false
{"z"=>-10}
false
{"z"=>-10}
true
nil
If I delete the if statement, I get the expected result of:
false
{"z"=>-10}
false
{"z"=>-10}
false
{"z"=>-10}
but having that if statement (or one like it) is kind of important.
Daniel Cusumano is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.