Skip to content

Instantly share code, notes, and snippets.

@Neener54
Created May 20, 2019 20:26
Show Gist options
  • Save Neener54/07b4d4e53b43cd2a515988bebbdce319 to your computer and use it in GitHub Desktop.
Save Neener54/07b4d4e53b43cd2a515988bebbdce319 to your computer and use it in GitHub Desktop.
Self Registering Class
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