Using && or and in Ruby

May 11, 2006 0 comments
Two reasons why I use && in my code:

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.

0 comments


Sorry, comments have been closed for this post.