Skip to content

Instantly share code, notes, and snippets.

@adrianobarroso
Created October 4, 2017 21:51
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 adrianobarroso/513ae731fa0bea985058cf426eee4e5e to your computer and use it in GitHub Desktop.
Save adrianobarroso/513ae731fa0bea985058cf426eee4e5e to your computer and use it in GitHub Desktop.
beatles = ["john", "ringo", "ringo", "seb"]
# beatles = [1, 2, 3, 4, 5, 6, 3]
# index => 0 1 2
#
# p beatles
# beatles[2] = "george"
# p beatles
# beatles.unshift("george")
# puts beatles.size
# #
# beatles.delete_at(2)
# puts beatles.size
beatles.each do |beatle|
unless beatle == "ringo"
puts "#{beatle} is in the Beatles"
else
puts "#{beatle} is sucks"
end
end
# for beatle in beatles
# puts "#{beatle} is in the Beatles"
# end
computer = ['cara', 'coroa'].sample
puts "cara ou coroa?"
response = gets.chomp
result = response == computer ? "ganhou" : "perdeu"
puts "Voce #{result} "
puts "Choose a number?"
number = gets.chomp.to_i
puts "The number #{number} is even" if number.even?
puts "The number #{number} is odd" if number.odd?
puts "What do you want to do (read|write|update)?"
action = gets.chomp
response = case action
when "read" then "READING"
when "write" then "WRITING"
when "update" then "UPDATING"
else
"Unkn"
end
p response
puts "Wagon".class
if nil
puts 1.class
puts 1.2.class
puts true.class
puts false.class
puts [1, 2, 3, 4].class
puts (1..6).class
end
random_number = rand(5)
while true
puts "Choose a number (0..4)"
num = gets.chomp.to_i
break if num == random_number
end
puts "You won"
puts "How old are you?"
age = gets.chomp.to_i
can_vote = (age >= 18) ? "You can vote" : "You cannot vote"
puts can_vote
puts "Que horas sao?"
hora = gets.chomp.to_i
morning_conditional = (hora > 9 && hora < 12)
afternoon_conditional = (hora > 14 && hora < 18)
cond = morning_conditional || afternoon_conditional
if cond
puts "Ta aberta"
else
puts "Ta fechada"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment