While I'm pulling data out of a form I'm trying to do this
unless v[:state_id] = 0 # Should be interpreted as the state_id
is the number zero.
what you're actually doing here is *assigning* (=) the value 0 to
your variable (returning that value, which in ruby is true), while
what you'd rather want is *testing* for equality (==).
While I’m pulling data out of a form I’m trying to do this
unless v[:state_id] = 0 # Should be interpreted as the state_id
is the number zero.
what you’re actually doing here is assigning (=) the value 0 to
your variable (returning that value, which in ruby is true), while
what you’d rather want is testing for equality (==).
Well I did try == 0 , and basically layed there like a dead mouse.
long story short: s/=/==/ will do the trick
what is this ? is this a typo , because this won’t parse .
unless v[:state_id] == 0
will return true only if v[:state_id] does not equal zero, is that what
you are wanting to do? Or do you want it to check if state_id is not
set? (unless v[:state_id])
unless v[:state_id] == 0
will return true only if v[:state_id] does not equal zero, is that what
you are wanting to do? Or do you want it to check if state_id is not
set? (unless v[:state_id])
If the state_id IS 0 (meaning the number zero). So I don’t think it should be == ,
I think it should be = , but I did a != 0 and that really mucked things up.
do something 'unless v[:state_id] is zero'
do something 'unless "setting v[:state_id] to zero evalutates to true"'
do something 'unless v[:state_id] is not zero'
> Exactly what are you trying to do?
> do something 'unless v[:state_id] is zero' <-------------- Yes this one.
do_something unless v[:state_id] == 0
or
unless v[:state_id] == 0
do_something
end
I suspect that your values are not what you think they are, or that you
are having trouble properly testing what is going on. If you are
testing for equality, you definitely, absolutely, always want a double
equals sign. That you were confused about that makes me think that your
life might become easier if you read a beginner's book on programming
in Ruby.
I’m not sure what is meant by equality but if I remember correctly from reading a beginner’s book,
equality is not the same as comparing one value to the next.
All I am trying to ask (Ruby) is the value in v[:state_id] zero. In that case I believe one set of equal signs is correct.
Let me know if I’m wrong or if there is some misunderstanding here.