Skip to content

Instantly share code, notes, and snippets.

@worace
Created February 12, 2015 19:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save worace/e7a0fdca58bf42425be6 to your computer and use it in GitHub Desktop.
Save worace/e7a0fdca58bf42425be6 to your computer and use it in GitHub Desktop.
Deaf Grandma Class-based refactoring
class Grandma
# returns true if the string
# is all caps
# otherwise returns false
def shouted?(string)
string == string.upcase
end
# returns true if you say "GOODBYE"
# otherwise returns false
def saying_goodbye?(string)
string == "GOODBYE"
end
def said_nothing?(string)
string.empty?
end
def converse
goodbye = 0
until goodbye > 1 do
response = gets.chomp
if saying_goodbye?(response)
goodbye = goodbye + 1
if goodbye < 2
puts "LEAVING SO SOON?"
end
elsif said_nothing?(response) #response.empty?
puts "WHAT?!"
elsif shouted?(response)
puts "NO, NOT SINCE 1946"
else
puts "SPEAK UP, KID!"
end
end
puts "LATER, SKATER!"
end
end
grandma = Grandma.new
grandma.converse
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment