Skip to content

Instantly share code, notes, and snippets.

@jancantor
Created March 15, 2014 23:56
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 jancantor/d1350ff41e4bca8f8ff6 to your computer and use it in GitHub Desktop.
Save jancantor/d1350ff41e4bca8f8ff6 to your computer and use it in GitHub Desktop.
#
# Expressions & Conditionals
#
games = ["Super Mario Bros.", "Contra", "Metroid", "Mega Man 2"]
# Unless
unless games.empty?
puts "Games in your vast collection: #{games.count}"
end
# Inline unless
puts "Games in your vast collection: #{games.count}" unless games.empty?
# If / Else
if games.empty?
puts "You don't have games in your collection"
else
puts "Games in your vast collection: #{games.count}"
end
# Inline If
puts "You don't have games in your collection." if games.empty?
# && / "AND"
if user && user.signed_in?
# Do something here...
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment