print "Ask the Magic 8-Ball your question: "
gets
puts Answers.find
Last active
November 6, 2015 20:22
-
-
Save mm53bar/e226fb9665ba69b05b82 to your computer and use it in GitHub Desktop.
Magic 8-ball
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 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 |
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
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