Possible Duplicate:
Ruby: difference between || and 'or'
In ruby, isn’t ‘or’ and ‘||’ the same thing? I get different results when I execute the code.
line =""
if (line.start_with? "[" || line.strip.empty?)
puts "yes"
end
line =""
if (line.start_with? "[" or line.strip.empty?)
puts "yes"
end
No, the two operators have the same effect but different precedence.
The
||operator has very high precedence, so it binds very tightly to the previous value. Theoroperator has very low precedence, so it binds less tightly than the other operator.The reason for having two versions is exactly that one has high precedence and the other has low precedence, since that is convenient.