Created
February 19, 2020 09:58
-
-
Save marcoranieri/ac4fd77c75190a66c4574f4949332d57 to your computer and use it in GitHub Desktop.
Flow & Array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cities = %w(rome paris perugia) | |
# ["rome", "paris", "perugia"] | |
# index 0 1 2 | |
# -3 -2 -1 | |
# READ | |
cities[1] | |
# CREATE | |
# cities.push("New York") | |
cities << "New York" | |
# UPDATE | |
cities[2] = "london" | |
# DELETE | |
cities.delete_at(3) | |
# cities.delete("New York") | |
p cities # puts cities.inspect | |
# _CRUD_ | |
# READ [index] | |
# CREATE << | |
# UPDATE [index] = | |
# DELETE delete_at(index) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
puts "What time is it?" | |
hour = gets.chomp.to_i | |
if hour < 12 | |
puts "Good morning" | |
elsif hour > 20 | |
puts "Good evening" | |
elsif hour > 12 | |
puts "Good afternoon" | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
puts "Which action?" | |
action = gets.chomp | |
# if action == "read" | |
# puts "Read mode" | |
# elsif action == "write" | |
# puts "Write mode" | |
# elsif action == "exit" | |
# puts "Exiting.." | |
# else | |
# puts "Invalid input" | |
# end | |
case action | |
when "read" then puts "Read mode" | |
when "write" then puts "Write mode" | |
when "exit" then puts "Exiting.." | |
else | |
puts "wrong input" | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
computer = rand(5) | |
guess = nil | |
# until guess == computer | |
while guess != computer | |
puts "Try again" | |
guess = gets.chomp.to_i | |
end | |
puts "You WIN!" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
puts "What time is it?" | |
hour = gets.chomp.to_i | |
is_morning = hour >= 9 && hour < 12 | |
is_afternoon = hour >= 15 && hour < 19 | |
if is_morning || is_afternoon | |
puts "It's open!" | |
else | |
puts "It's close.." | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# puts "How old are you?" | |
# age = gets.chomp.to_i | |
# if age >= 18 | |
# puts "you can vote" | |
# else | |
# puts "you cannot vote" | |
# end | |
# # condition ? true_block : false_block | |
# answer = age >= 18 ? "you can vote" : "you cannot vote" | |
# puts answer | |
# HEADS or TAILS | |
computer = ["heads", "tails"].sample | |
puts "Heads or Tails?" | |
answer = gets.chomp | |
outcome = answer == computer ? "Win" : "Lost" | |
puts outcome | |
# number.even? ? "EVEN" : "ODD" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
puts "How old are you?" | |
age = gets.chomp.to_i | |
# if !age >= 18 | |
unless age >= 18 | |
puts "you can vote" | |
else | |
puts "you cannot vote kiddo!" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment