Skip to content

Instantly share code, notes, and snippets.

@cappert
Last active May 2, 2016 18:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cappert/b896739d7e8a3045c5d41be05a4af4e9 to your computer and use it in GitHub Desktop.
Save cappert/b896739d7e8a3045c5d41be05a4af4e9 to your computer and use it in GitHub Desktop.

#Unless

Sometimes you want to use control flow to check if something is false, rather than if it's true. You could reverse your if/else, but Ruby will do you one better: it will let you use an unless statement.

Let's say you don't want to eat unless you're hungry. That is, while you're not hungry, you write programs, but if you are hungry, you eat. You might write that program in Ruby like this:

unless hungry
  # Write some sweet programs
else
  # Have some noms
end
@cappert
Copy link
Author

cappert commented May 2, 2016

weird to see Codecademy promote unless... else, it's bad practice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment