Created
March 19, 2014 17:12
-
-
Save cheeyeo/9646460 to your computer and use it in GitHub Desktop.
Ruby polymorphic example
This file contains hidden or 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 GenericParser | |
def parse(parser) | |
puts "The parser class received the parse method" | |
parser.parse | |
end | |
end | |
class JSONParser | |
def parse | |
puts "An instance of the JSONParser receives the parse message" | |
end | |
end | |
class XmlParser | |
def parse | |
puts "An instance of the XmlParser receives the parse message" | |
end | |
end | |
# parser = GenericParser.new | |
# puts 'Using the XmlParser' | |
# parser.parse(XmlParser.new) | |
# puts 'Using the JsonParser' | |
# parser.parse(JsonParser.new) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment