Mercurial > repos > other > SevenLanguagesInSevenWeeks
view 1-Ruby/day1-irb.output @ 16:8d46064c9afc
Be a nice Ruby user and follow block convention for do/end vs {}
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Tue, 03 Jan 2017 20:38:45 +0000 |
parents | 3e4ea3d47880 |
children |
line wrap: on
line source
day1.rb(main):001:0> #! /usr/bin/env ruby day1.rb(main):002:0* day1.rb(main):003:0* puts 'Hello, World' Hello, World => nil day1.rb(main):004:0> puts 'Hello, Ruby'.index('Ruby') 7 => nil day1.rb(main):005:0> i = 1 => 1 day1.rb(main):006:0> day1.rb(main):007:0* while i <= 10 day1.rb(main):008:1> puts "This is sentence number #{i}" day1.rb(main):009:1> i = i + 1 day1.rb(main):010:1> end This is sentence number 1 This is sentence number 2 This is sentence number 3 This is sentence number 4 This is sentence number 5 This is sentence number 6 This is sentence number 7 This is sentence number 8 This is sentence number 9 This is sentence number 10 => nil day1.rb(main):011:0> day1.rb(main):012:0* day1.rb(main):013:0* randNum = rand(10) => 3 day1.rb(main):014:0> guess = 11 => 11 day1.rb(main):015:0> until guess == 'q' or guess.to_i == randNum day1.rb(main):016:1> puts 'Guess the number (0-9) or "q" to quit' day1.rb(main):017:1> guess = gets.strip day1.rb(main):018:1> end Guess the number (0-9) or "q" to quit Guess the number (0-9) or "q" to quit Guess the number (0-9) or "q" to quit Guess the number (0-9) or "q" to quit Guess the number (0-9) or "q" to quit Guess the number (0-9) or "q" to quit => nil day1.rb(main):019:0> day1.rb(main):020:0* puts "Well done! The number was #{randNum}" unless guess == 'q'day1.rb(main):020:0* day1.rb(main):020:0> Well done! The number was 3 => nil