Created
January 17, 2011 16:20
-
-
Save botanicus/783038 to your computer and use it in GitHub Desktop.
respond_to_missing?(method, _)
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 RockPaperScissorsGame | |
PATTERNS ||= [:rock, :paper, :scissors] | |
def respond_to_missing?(method, _) | |
PATTERNS.include?(method) || super(method) | |
end | |
def method_missing(guess, *args, &block) | |
if PATTERNS.include?(guess) | |
puts "You played #{guess}!" | |
else | |
super(guess, *args, &block) | |
end | |
end | |
end | |
game = RockPaperScissorsGame.new | |
game.rock | |
p game.respond_to?(:rock) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment