Mysterious nil variable in submit.yml.erb

Here is some example code that I have tested in my submit.yml.erb. First it asserts that gpus is not nil, and then it passes gpus into a function, and then that function asserts again that it is not nil.

<%
def foo(x)
    if x.nil?
    	raise Exception.new("x is nil!")
    end
    return x
end
if gpus.nil?
    raise Exception.new("gpus is nil!")
end
gpus = foo(gpus)
%>

The outer assertion passes, and the inner assertion fails.
If I change the last line from gpus = foo(gpus) to something_else = foo(gpus), both assertions pass.
Is it illegal in Ruby to use a variable in an expression and then overwrite the variable in the same line?

That is interesting. It must be something with the way ERB is handling the scope and reassignment. I don’t think it’s a Ruby thing especially, more of a hyper-specific Ruby ERB/scoping thing while it’s evaluating everything.

Which is to say - I can replicate, but I’m not sure why that’s the case.

As an aside though - you shouldn’t be raising Exceptions instead just raise("the message") (throwing a StandardError) as this is handled better by OnDemand.