Skip to content

Instantly share code, notes, and snippets.

@gboone gboone/til.rb
Created Jan 20, 2016

Embed
What would you like to do?
Today I Learned about ruby logic
# 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
You can’t perform that action at this time.