Module#recursive_const_get

class Module
  def recursive_const_get(name)
    name.to_s.split("::").inject(self) do |b, c|
      b.const_get(c)
    end
  end
end

Example

module Foo
  BAR = "Hello World!" 
end

Module.const_get("Foo::BAR") rescue $!
# => #<NameError: wrong constant name Foo::BAR>

Module.const_get("Foo").const_get("BAR")
# => "Hello World!"

Module.recursive_const_get("Foo::BAR")
# => "Hello World!"