Reputation: 8706
I understand the difference between them, but I can't work out why they're both included in the language. Surely having both just causes confusion?
Upvotes: 1
Views: 160
Reputation: 44080
I believe one should look no further.
Upvotes: 2
Reputation: 230336
Their precedence is different, so they are not equivalent.
My rule of thumb is as follows: use &&
for logical expressions and use and
for control flow.
# logical expressions
if user.first_name == 'Bob' && user.last_name == 'Jones'
# control flow
worker.do_this and worker.and_also_do_this_if_that_went_well
Upvotes: 5
Reputation: 24399
This is the best explanation I've seen:
http://avdi.org/devblog/2010/08/02/using-and-and-or-in-ruby/
Upvotes: 0
Reputation: 4103
Do go through this: http://phrogz.net/ProgrammingRuby/language.html#andornotanddefined
Upvotes: 1