# File lib/extlib/module.rb, line 6 6: def find_const(const_name) 7: if const_name[0..1] == '::' 8: Object.full_const_get(const_name[2..1]) 9: else 10: nested_const_lookup(const_name) 11: end 12: end
Doesn’t do any caching since constants can change with remove_const
# File lib/extlib/module.rb, line 21 21: def nested_const_lookup(const_name) 22: unless equal?(Object) 23: constants = [] 24: 25: name.split('::').each do |part| 26: const = constants.last || Object 27: constants << const.const_get(part) 28: end 29: 30: parts = const_name.split('::') 31: 32: # from most to least specific constant, use each as a base and try 33: # to find a constant with the name const_name within them 34: constants.reverse_each do |const| 35: # return the nested constant if available 36: return const if parts.all? do |part| 37: const = if RUBY_VERSION >= '1.9.0' 38: const.const_defined?(part, false) ? const.const_get(part, false) : nil 39: else 40: const.const_defined?(part) ? const.const_get(part) : nil 41: end 42: end 43: end 44: end 45: 46: # no relative constant found, fallback to an absolute lookup and 47: # use const_missing if not found 48: Object.full_const_get(const_name) 49: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.