Skip to content

Instantly share code, notes, and snippets.

@cheeyeo
Created March 19, 2014 17:12
Show Gist options
  • Save cheeyeo/9646460 to your computer and use it in GitHub Desktop.
Save cheeyeo/9646460 to your computer and use it in GitHub Desktop.
Ruby polymorphic example
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