Programming Tutorials

unless in Ruby on rails

By: Brian Marick in Ruby Tutorials on 2008-10-17  

The word "unless" is in the English language for a reason. Contrast "unless the judge is unfair, you'll win" with "if the judge is not unfair, you'll win." Negations - especially negations of already negative ideas can be confusing. The same is true of Ruby code:

unless unfair(judge)
winner = you
if not unfair(judge)
winner = you

You can also use unless with the one-line form:

array.pop unless array.empty?

Add Comment

* Required information


No comments yet. Be the first!

Most Viewed Articles (in Ruby )

Latest Articles (in Ruby)