Skip to content

Instantly share code, notes, and snippets.

@marcoranieri
Created October 9, 2019 10:32
Show Gist options
  • Save marcoranieri/a6be3501b9e1db3622be00cca4e6e709 to your computer and use it in GitHub Desktop.
Save marcoranieri/a6be3501b9e1db3622be00cca4e6e709 to your computer and use it in GitHub Desktop.
Flow & Array
beatles = ["john", "ringo", "seb"]
#index 0 1 2 (length - 1)
#index -3 -2 -1
p beatles # puts beatles.inspect
# C R U D
# Create
beatles << "marco"
# beatles.insert(1, "marco")
p beatles
# Read
beatles[0]
# Update
beatles[2] = "george"
p beatles
# Delete
beatles.delete_at(3)
beatles.delete("george")
p beatles
puts "Insert a number"
num = gets.chomp.to_i
condition ? true : false_part
puts num.even? ? "Even" : "Odd"
computer = ["tails", "heads"].sample
puts "what's your guess"
user = gets.chomp.downcase
# if user == computer
# puts "you win"
# else
# puts "you lose"
# end
message = user == computer ? "you win" : "you lose"
puts message
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
puts "Insert action"
action = gets.chomp
# if action == "read"
# puts "Entering read mode"
# elsif action == "write"
# puts "Entering write mode"
# elsif action == "exit"
# puts"Exit!"
# else
# puts "Wrong input"
# end
case action
when "read"
puts "Entering read mode"
break
when "write"
puts "Entering write mode"
when "exit"
puts "Exit!"
else
puts "Wrong"
end
puts "What time is it?"
hour = gets.chomp.to_i
# AND OR AND
# if hour > 9 && hour < 12 || hour > 15 && hour < 18
# puts "Open!"
# end
is_morning = hour > 9 && hour < 12
is_afternoon = hour > 15 && hour < 18
if is_morning || is_afternoon
puts "Open!"
end
# if condition
# block
# end
puts "What's yor age?"
age = gets.chomp.to_i
if age >= 18
puts "you can vote"
else
puts "you cannot vote"
end
# condition ? true_part : false_part
# result = age >= 18 ? "you can vote" : "you cannot vote"
puts result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment