Created
March 23, 2010 21:17
-
-
Save amiel/341666 to your computer and use it in GitHub Desktop.
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
def Object.const_get_or_set_class klass_name | |
klass_name = klass_name.gsub(/(^|_)(.)/) { $2.upcase } | |
const_defined?(klass_name) ? const_get(klass_name) : const_set(klass_name, Class.new) | |
end | |
module Foo; end | |
def Foo.de(bar) | |
Object.const_get_or_set_class "foo_de_#{bar}" | |
end |
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
Foo.de :bar # => FooDeBar | |
Foo.de :bar_barr # => FooDeBarBarr |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment