Created
February 12, 2015 19:03
-
-
Save worace/e7a0fdca58bf42425be6 to your computer and use it in GitHub Desktop.
Deaf Grandma Class-based refactoring
This file contains 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 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