A Post Entitled …and?

posted 1 year ago

‘and’ and ‘or’ originate (like so much of Ruby) in Perl. In Perl, they were largely used to modify control flow, similar to the ‘if’ and ‘unless’ statement modifiers. A common Perl idiom is:

do_something() or die “It didn’t work!”;

The ‘and’ and ‘or’ keywords serve the same purpose in Ruby. Properly understood, ‘and’ and ‘or’ are control flow operators, not boolean operators.

I just ran across the quote above in Avdi’s explanation of ‘and’ vs ‘&&’. I almost skipped the article but am glad that I read it. This may be the first time that I have seen an explanation of why the operators differ rather than how they differ. The former makes it much easier to remember the difference. Thanks, Avdi!

Comments

About this site and its Author


The Tumblrs to Follow

  • staff
  • cdmwebs
  • paulsullivanjr
  • dawnvanasse
  • bitbltr