Created
October 26, 2015 00:21
-
-
Save noam87/8878875201ad32631157 to your computer and use it in GitHub Desktop.
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 Conversation | |
GOOD_ANSWERS = ["great", "awesome", "radical", "good"] | |
BAD_ANSWERS = ["shitty", "terrible", "bad"] | |
def initialize | |
@ended = false | |
end | |
def ended | |
@ended | |
end | |
def ask_for_name | |
puts("Hey, what's your name?") | |
@name = gets.chomp | |
end | |
def greet | |
if last_name | |
puts("Why, hello, Mr or Mrs #{last_name}") | |
else | |
puts("Oh, nice to meet you, #{first_name}.") | |
end | |
end | |
def ask_about_day | |
puts("How was your day?") | |
@day = gets.chomp | |
end | |
def end_conversation | |
if GOOD_ANSWERS.include?(@day) | |
puts("Oh, great! I too had a good day.") | |
elsif BAD_ANSWERS.include?(@day) | |
puts("Aw, muffin. I'm sorry to hear.") | |
else | |
puts("Huh.") | |
end | |
puts("Your response is so interesting, that I will save it for later!") | |
File.open('somefile', 'w') { |file| file.write("#{@name} had a #{@day} day") } | |
end | |
def end_conversation? | |
puts("I am a lonely old woman and everyone hates me. Would you please keep talking to me?") | |
keep_talking = gets.chomp | |
@ended = true if keep_talking.split(" ").include?("no") | |
end | |
private | |
def first_name | |
@name.split(" ")[0] | |
end | |
def last_name | |
@name.split(" ")[1] | |
end | |
end | |
conversation = Conversation.new | |
conversation.ask_for_name | |
conversation.greet | |
while conversation.ended == false | |
conversation.ask_about_day | |
conversation.end_conversation | |
conversation.end_conversation? | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment