Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- =begin
- Hello everyone, finally my summer vacations started, so, it's time for a new challenge. This time I will read a book called "Seven Languages in Seven Weeks". Ruby is the first language, and, this is some exercises from day 1. Everyday has exercises, so, I will try to share the most I can. I hope everyone like. Have a nice day ;)
- =end
- # Exercise (1)
- puts 'Ola mundo!'
- # Exercise (2)
- strToSearch = 'Ola, Ruby'
- strToSearch.index('Ruby')
- # Exercise (3)
- i = 0
- while(i < 10)
- puts 'O meu nome'
- i = i + 1
- end
- # Exercise (4)
- i = 1
- while(i <= 10)
- puts "Este é o número #{i}"
- i = i + 1
- end
- # Exercise (5)
- #------myruby.rb------
- #!/usr/bin/env ruby
- puts 'Ola mundo'
- #---------------------
- =begin
- then just "ruby myruby.rb" in command line
- or (if using linux)
- (a) just be sure your file executable by running "chmod +x myruby.rb"
- (b) and run "./myruby"
- Thanks to http://stackoverflow.com/questions/8721369/how-to-execute-a-ruby-script-in-terminal
- =end
- # BONUS Exercise
- #------guessnumber.rb------
- #!/usr/bin/env ruby
- randNumber = rand(10)
- found = 0
- puts 'Which number between 0 and 10 the program chosen?'
- begin
- input = gets
- number = input.chomp.to_i
- if number == randNumber then
- puts 'Congrats! You found the number!'
- found = 1
- else
- puts 'Wrong answer, try again.'
- end
- end until found == 1
- #---------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement