This is my brain on reason.

Deaf Grandma – Ruby Code

Written by Chantal in category 
May 18, 2008
I’m working on Learn to Program by Chris Pine. This is one of the exercises mentioned in chapter 7 (chapter 6 in the online version).

Poor Grandma can’t hear very well. You really have to scream at her, but even then, she doesn’t quite hear what you’re saying. You have to be careful too because she often tries to plant sloppy, toothless Grandma kisses on you.

# Deaf Grandma with random years

say = ‘Ew. Grandma wants a kiss!’
puts ‘Grandma stares vacantly at you…’

while say != ‘BYE’
# STDOUT.flush
say = gets.chomp
puts
puts “You say, ‘#{say}.'”
if say == say.upcase
# She hears you … sort of
year = (2007 – rand(101))
puts “Grandma says, ‘NO, NOT SINCE #{year}!'”
else
# She yells at you
puts “Grandma says, ‘HUH?! SPEAK UP!'”
end
end
puts
puts ‘You head for the hills before Grandma steals a kiss …’

Unless you YELL at Grandma (in uppercase), she just complains that she can’t hear you. When she does hear you, she’ll just say something in reference to a random year in the past. When it’s time to leave, you have to yell ‘BYE’ to her (or just wait for her to doze off in her rocking chair).

  • http://rubylearning.org Jeff Hales

    I got that book right after signing up for the course at rubylearning.org. It’s awesome and goes very well with the curriculum. Can you tell my socks aren’t on backwards today? :-) See you in class!

  • http://chantal13.com Chantal

    The book is awesome. It’s very rare that you get to read a programming book that makes you laugh and learn something at the same time.