Created
January 20, 2016 23:07
-
-
Save gboone/5f2562564c9dfddf38f8 to your computer and use it in GitHub Desktop.
Today I Learned about ruby logic
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# this: | |
if expected['value'] | |
variable = expected['value'] | |
else | |
variable = "default" | |
end | |
# is the same as this: | |
unless variable = expected['value'] | |
variable = "default" | |
end | |
### | |
# In the first example, `variable` is set to `expected['value']` if `expected['value']` | |
# is set and return false if it's not. Returning `false` will, of course, send the | |
# program to the `else` condition, assigning `variable` to `"default"`. | |
# | |
# In the second it will set `variable` to `expected['value']` if it can, and "default" | |
# if the conditional evaluates `false`. | |
### |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment