Skip to content

Instantly share code, notes, and snippets.

@jgaskins
Created June 9, 2013 16:23
Show Gist options
  • Save jgaskins/5744146 to your computer and use it in GitHub Desktop.
Save jgaskins/5744146 to your computer and use it in GitHub Desktop.
Much leaner version of ActiveSupport's String#constantize
class String
def constantize
split('::').inject(Kernel, &:const_get)
end
end
A, A::B = Module.new, Class.new
p "A::B".constantize # => A::B
p "Object".constantize # => Object
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment