Skip to content

Instantly share code, notes, and snippets.

@amiel
Created March 23, 2010 21:17
Show Gist options
  • Save amiel/341666 to your computer and use it in GitHub Desktop.
Save amiel/341666 to your computer and use it in GitHub Desktop.
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
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