Skip to content

Instantly share code, notes, and snippets.

@ugisozols
Created July 26, 2010 11:32
Show Gist options
  • Save ugisozols/490439 to your computer and use it in GitHub Desktop.
Save ugisozols/490439 to your computer and use it in GitHub Desktop.
class Granny
attr_reader :name
def initialize(name)
@name = name
end
end
class Conversation
attr_reader :grannys
def initialize
@grannys = []
@phrases = []
end
def random_granny
@grannys[rand(@grannys.size)].name
end
def add_response
@phrases << yield
end
def get_response
@phrases[rand(@phrases.size)]
end
end
conversation = Conversation.new
conversation.grannys << Granny.new('Kara')
conversation.grannys << Granny.new('Milda')
conversation.grannys << Granny.new('Abby')
conversation.add_response { 'Can\'t you see I\'m watching tely?!' }
conversation.add_response { "NO NOT SINCE #{1930 + rand(21)}" }
conversation.add_response { 'Kill one man, and you are a murderer. Kill millions of men, and you are a conqueror. Kill them all, and you are a god' }
conversation.add_response { "I don't know so you'll better ask #{conversation.random_granny}..." }
puts 'Whats on your mind?'
until (input = gets.strip!).eql?('BYE')
puts "#{conversation.random_granny}: #{conversation.get_response}!" unless input.empty?
end
conversation.grannys.each { |granny| puts "#{granny.name}: BYE!" }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment