Sha256: 76ccc268d09b6d6bda053022e2a7bab890b0f4eca2f3e17019e9294cdbbe9413
Contents?: true
Size: 731 Bytes
Versions: 11
Compression:
Stored size: 731 Bytes
Contents
# From: http://redcorundum.blogspot.com/2006/05/kernelqualifiedconstget.html # We need this to properly handle namespaced class resolution in Candy::Wrapper.unwrap. module Kernel def qualified_const_get(str) path = str.to_s.split('::') from_root = path[0].empty? if from_root from_root = [] path = path[1..-1] else start_ns = ((Class === self)||(Module === self)) ? self : self.class from_root = start_ns.to_s.split('::') end until from_root.empty? begin return (from_root+path).inject(Object) { |ns,name| ns.const_get(name) } rescue NameError from_root.delete_at(-1) end end path.inject(Object) { |ns,name| ns.const_get(name) } end end
Version data entries
11 entries across 11 versions & 1 rubygems