Using && or and in Ruby
May 11, 2006
0 comments
Two reasons why I use && in my code:
- The Rails source does
- I learned to program in C++ so the following is downright scary
a = 'test'
b = nil
both = a && b # both == nil
both = a and b # both == 'test'
both = (a and b) # both == nil
One reason why using and is better:
- It reads well
You will get bitten very hard (I have more times than I care to recall) if you don’t pay close attention to which one you’re using, so I prefer using && everywhere now.
Sorry, comments have been closed for this post.