Skip to content

Instantly share code, notes, and snippets.

@botanicus
Created January 17, 2011 16:20
Show Gist options
  • Save botanicus/783038 to your computer and use it in GitHub Desktop.
Save botanicus/783038 to your computer and use it in GitHub Desktop.
respond_to_missing?(method, _)
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