Created
May 22, 2011 20:48
-
-
Save raywu/985874 to your computer and use it in GitHub Desktop.
Chris Pine's exercises
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
def deafGrandma | |
grandma = '' | |
while grandma != 'BYE' | |
grandma = gets.chomp | |
if grandma == grandma.upcase | |
puts 'NO, NOT SINCE 1938!' | |
else | |
puts 'HUH, SPEAK UP, SONNY!' | |
end | |
end | |
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
def deafGrandma | |
puts "HEY SONNY!" | |
bye = 0 | |
while bye < 3 | |
grandma = gets.chomp | |
if grandma == "BYE" | |
puts "HMM...I'D RATHER..." | |
bye = (bye+1) | |
elsif grandma == grandma.upcase | |
puts "NO! NOT SINCE 1938!" | |
else | |
puts "HUH, I CAN'T HEAR YOU!" | |
end | |
end | |
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
class Die | |
def initialize | |
roll | |
end | |
def roll | |
@numberShowing = 1 + rand(6) | |
end | |
def showing | |
@numberShowing | |
end | |
def cheat | |
if @numberShowing == 1 | |
@numberShowing | |
else | |
@numberShowing - 1 | |
end | |
end | |
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
def ethnicfood | |
languages = ["German", "Chinese", "Japanese", "French"] | |
languages.each do |l| | |
puts "I love " + l + " food!" | |
puts "Don\'t you?" | |
end | |
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
def favoritenumber | |
puts 'What\'s is your favorite number?' | |
fNumber = gets.chomp.to_i | |
puts 'Oh, really? Why not ' + (fNumber + 1).to_s + '?' | |
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
def name | |
puts 'What is your first name?' | |
firstname = gets.chomp | |
puts 'What is your last name?' | |
lastname = gets.chomp | |
puts 'Hi ' + firstname + ' ' + lastname + ', pleased to meet you!' | |
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
def nameLength | |
puts "What is your first name?" | |
firstname = gets.chomp | |
puts "What is your middle name?" | |
middlename = gets.chomp | |
puts "What is your last name?" | |
lastname = gets.chomp | |
puts "Awesome, your full name has " + (firstname.length + middlename.length + lastname.length).to_s + " characters in it!" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment