Skip to content

Instantly share code, notes, and snippets.

@fj
Created April 25, 2010 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fj/378435 to your computer and use it in GitHub Desktop.
Save fj/378435 to your computer and use it in GitHub Desktop.
# Given a constant's name of the form r = "One::Two::[...]::ThirtyFive",
# resolve its value.
sep = "::" # Doesn't appear that '::' is defined.
c = r.split(sep).inject(Object) { |memo, el| memo.const_get(el) }
# Usage:
module Foo
module Bar
Baz = 100
end
end
r = "Foo::Bar::Baz"
c = r.split(sep).inject(Object) { |memo, el| memo.const_get(el) }
# => 100
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment