Skip to content

Instantly share code, notes, and snippets.

@tjsingleton
Forked from plukevdh/parser_plugin.rb
Created April 26, 2011 03:50
Show Gist options
  • Save tjsingleton/941767 to your computer and use it in GitHub Desktop.
Save tjsingleton/941767 to your computer and use it in GitHub Desktop.
A nonsensical example of what I want to do. Someone please fill in the blanks.
module Parser
@formats = {}
class << self
attr_accessor :formats
def create(format)
formats[format].new
end
end
class Base
def self.inherited(subclass)
format = subclass.to_s.split('::').last.downcase.to_sym
Parser.formats[format] = subclass
end
end
end
class Parser::Html < Parser::Base
end
class Parser::Pdf < Parser::Base
end
parser = Parser.create(type: :html)
parser.class
@plukevdh
Copy link

yeah, that's helpful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment