Skip to content

Instantly share code, notes, and snippets.

@sorokadima
Last active January 11, 2020 10:45
Show Gist options
  • Save sorokadima/d3dfb416209aa5e77373839f9d18830a to your computer and use it in GitHub Desktop.
Save sorokadima/d3dfb416209aa5e77373839f9d18830a to your computer and use it in GitHub Desktop.
Ruby unless && statement (unless or and, Ruby Draft)
a = true
b = false
# if one of variable false run exception
if !a or !b
p 'ERROR 1' # +
end
unless a or b
p 'ERROR 2' # -
end
unless a and b
p 'ERROR 3' # +
end
# Screenshot: https://dl.dropboxusercontent.com/s/nsfx4h8k3318ota/Screenshot%20at%2012-28-36.png
# Ruby first evaluates the values of both variables and then checks whether FALSE
unless (false)
p 'ERROR'
end
# TRUE if all variables is true
> true and false
=> false
# TRUE if at least one of variables is true
> true or false
=> true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment