Sha256: 381c0aad03f2dc5e97c42ddc1f591912d8cf00e1d07079fa1a41b52dfc574109
Contents?: true
Size: 902 Bytes
Versions: 12
Compression:
Stored size: 902 Bytes
Contents
# From http://redcorundum.blogspot.com/2006/05/kernelqualifiedconstget.html # Adapted into a module, rather than monkey patching it into Kernel # # Method to take a string constant name, including :: qualifications, and # look up the actual constant. Looks up relative to current file. # REspects leading ::. Etc. module Traject::QualifiedConstGet 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
12 entries across 12 versions & 1 rubygems