Skip to content

Instantly share code, notes, and snippets.

@marcoranieri
Last active February 19, 2020 19:10
Show Gist options
  • Save marcoranieri/12ea49c9835598c5e06a475ef09d66de to your computer and use it in GitHub Desktop.
Save marcoranieri/12ea49c9835598c5e06a475ef09d66de to your computer and use it in GitHub Desktop.
Flow & Array
def acronomize(sentence)
return "" if sentence == ""
#retrieve each word from sentence (from string to array)
sentence_array = sentence.split(" ")
#take just first letter from each word and capitalize
acronym = []
sentence_array.each do |word|
#store in new array
acronym.push(word[0].upcase)
end
#join array and return (as string!)
return acronym.join
end
puts acronomize("be right back")
puts acronomize("laugh out loud")
puts acronomize("be right back") == "BRB"
puts acronomize("laugh out loud") == "LOL"
puts acronomize("") == ""
# Define our OPTIONS
OPTIONS = ["rock", "paper", "scissors"] # OPTIONS is a Constant
# Computer input
computer = OPTIONS.sample
# User input
puts "Choose an option: #{OPTIONS.join(" - ")}"
choice = gets.chomp
# Compare the choices + display the outcome
if choice == computer
puts "Draw"
elsif (choice == "rock") && (computer == "scissors") ||
(choice == "paper") && (computer == "rock") ||
(choice == "scissors") && (computer == "paper")
puts "You win!"
else
puts "You lose!"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment