Skip to content

Instantly share code, notes, and snippets.

@ryanckulp
Created January 2, 2018 03:55
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 ryanckulp/d7eda5eb9d0ae2ccb3285311724faa8f to your computer and use it in GitHub Desktop.
Save ryanckulp/d7eda5eb9d0ae2ccb3285311724faa8f to your computer and use it in GitHub Desktop.
example if/guard clause in Ruby
# verbose
if 2 + 2 == 4
puts "Correct!"
end
# short-hand
puts "Correct" if 2 + 2 == 4
# more realistic short-hand
def addition_problem(user_answer, correct_answer)
puts "Correct" if user_answer == correct_answer
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment