Skip to content

Instantly share code, notes, and snippets.

@mm53bar
Last active November 6, 2015 20:22
Show Gist options
  • Save mm53bar/e226fb9665ba69b05b82 to your computer and use it in GitHub Desktop.
Save mm53bar/e226fb9665ba69b05b82 to your computer and use it in GitHub Desktop.
Magic 8-ball

Magic 8-Ball

print "Ask the Magic 8-Ball your question: "
gets
puts Answers.find
class Answers
ANSWERS = [
"It is certain",
"It is decidedly so",
"Without a doubt",
"Yes, definitely",
"You may rely on it",
"As I see it, yes",
"Most likely",
"Outlook good",
"Yes",
"Signs point to yes",
"Reply hazy try again",
"Ask again later",
"Better not tell you now",
"Cannot predict now",
"Concentrate and ask again",
"Don't count on it",
"My reply is no",
"My sources say no",
"Outlook not so good",
"Very doubtful"
]
def initialize(answers = ANSWERS)
@answers = answers
end
def self.find
self.new.find
end
def find
answers.sample
end
private
attr_reader :answers
end
require "./answers.rb"
require "minitest/autorun"
class TestAnswers < Minitest::Test
def setup
@answers = Answers.new
end
def test_that_it_returns_results
refute_nil @answers.find
end
def test_that_it_accepts_new_answers
answers = ["No idea", "Screw off"]
assert_includes answers, Answers.new(answers).find
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment