Skip to content

Instantly share code, notes, and snippets.

@minikermit
Created August 17, 2010 22:21
Show Gist options
  • Save minikermit/532378 to your computer and use it in GitHub Desktop.
Save minikermit/532378 to your computer and use it in GitHub Desktop.
A common idiom is to use || to assign a value to a variable only if that variable isn't already set. This can be written as:
1. @variable = @variable || "default value"
@variable = @variable || "default value"
or, more idiomatically, as:
1. @variable ||= "default value"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment