Created
May 20, 2019 20:26
-
-
Save Neener54/07b4d4e53b43cd2a515988bebbdce319 to your computer and use it in GitHub Desktop.
Self Registering Class
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
module Types | |
module Registry | |
REGISTRATIONS = {} | |
def mime_type(string) | |
REGISTRATIONS[string] = self | |
end | |
def self.handle_type(string) | |
handler_klass = REGISTRATIONS[string].new | |
handler_klass.process | |
end | |
end | |
class XML | |
extend Registry | |
mime_type "string/xml" | |
def process | |
puts "Yay" | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment