Skip to content

Instantly share code, notes, and snippets.

@raywu
Created May 22, 2011 20:48
Show Gist options
  • Save raywu/985874 to your computer and use it in GitHub Desktop.
Save raywu/985874 to your computer and use it in GitHub Desktop.
Chris Pine's exercises
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
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
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
def ethnicfood
languages = ["German", "Chinese", "Japanese", "French"]
languages.each do |l|
puts "I love " + l + " food!"
puts "Don\'t you?"
end
end
def favoritenumber
puts 'What\'s is your favorite number?'
fNumber = gets.chomp.to_i
puts 'Oh, really? Why not ' + (fNumber + 1).to_s + '?'
end
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
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