Created
April 26, 2011 03:11
-
-
Save plukevdh/941725 to your computer and use it in GitHub Desktop.
A nonsensical example of what I want to do. Someone please fill in the blanks.
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 Parser | |
class << Base | |
# what to do here? | |
def create(sym) | |
eval 'Parser::#{sym.to_s.capitalize}.new' | |
end | |
end | |
end | |
class Parser::Html < Parser::Base | |
end | |
class Parser::Pdf < Parser::Base | |
end | |
parser = Parser.create(type: :html) | |
parser.class | |
#> Parser::Base::Html |
yeah, that's helpful. definitely planning on many parsers. I want it to be extendable so others can write plugins as well.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Are you planning on many parsers, or just a small subset? and there is a better way than eval
Object.get_const("Parser::#{sym.to_s.capitalize}").new