Created
October 4, 2017 21:51
-
-
Save adrianobarroso/513ae731fa0bea985058cf426eee4e5e to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| 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 |
This file contains hidden or 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 = ['cara', 'coroa'].sample | |
| puts "cara ou coroa?" | |
| response = gets.chomp | |
| result = response == computer ? "ganhou" : "perdeu" | |
| puts "Voce #{result} " |
This file contains hidden or 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 "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? |
This file contains hidden or 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 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 |
This file contains hidden or 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 "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 |
This file contains hidden or 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
| 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" |
This file contains hidden or 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 | |
| can_vote = (age >= 18) ? "You can vote" : "You cannot vote" | |
| puts can_vote |
This file contains hidden or 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 "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