Title: I'm sure many of you guys and gals know this. And it might be just one of those things that I have somehow missed during all my time coding QBASIC, VBA, C++, C, Ruby, Python, etc...<p>Most of the time when you are writing an if statement, you are comparing a mutable variable to something constant (i.e. variable to string, variable to integer, variable to symbol), so you can avoid the assignment-instead-of-comparison bug by writing constant == variable instead of variable == constant. This way if you forget one of the equals signs you'll get a syntax error. The key with this is you have to get in the habit of doing it and do it all the time, so that you don't have a false sense of security. 
So instead of:<p>if foo.to_str == "hi everyone!\n"<p><pre><code>  puts "hello there!"  
</code></pre>
end<p>use<p>if "hi everyone!\n" == foo.to_str<p><pre><code>  puts "hello there!"  
</code></pre>
end
Upvote: