Created
June 1, 2018 21:26
-
-
Save lchanmann/ee385fd71bd0f05f1d1d0b2cc4a3dc23 to your computer and use it in GitHub Desktop.
bob_bot_5
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
# Base | |
class Base | |
attr_reader :message | |
def initialize(message) | |
@message = message | |
end | |
def valid? | |
!message.nil? | |
end | |
def accept(visitor) | |
raise "Not yet implemented" | |
end | |
end | |
# Question | |
class Question < Base | |
def valid? | |
super && message.end_with?("?") | |
end | |
def accept(visitor) | |
visitor.respond_to_question | |
end | |
end | |
# Yell | |
class Yell < Base | |
def valid? | |
super && | |
!message.strip.empty? && | |
message == message.upcase && | |
message != message.to_i.to_s | |
end | |
def accept(visitor) | |
visitor.respond_to_yell | |
end | |
end | |
# Silence | |
class Silence < Base | |
def valid? | |
super && message.strip.empty? | |
end | |
def accept(visitor) | |
visitor.respond_to_silence | |
end | |
end | |
# Anything | |
class Anything < Base | |
def valid? | |
super && true | |
end | |
def accept(visitor) | |
visitor.respond_to_anything | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment