Method: JSON.deep_const_get
- Defined in:
- lib/json/common.rb
.deep_const_get(path) ⇒ Object
Return the constant located at path. The format of path has to be either ::A::B::C or A::B::C. In any case, A has to be located at the top level (absolute namespace path?). If there doesn’t exist a constant at the given path, an ArgumentError is raised.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/json/common.rb', line 36 def deep_const_get(path) # :nodoc: path.to_s.split(/::/).inject(Object) do |p, c| case when c.empty? then p when p.const_defined?(c, true) then p.const_get(c) else begin p.const_missing(c) rescue NameError => e raise ArgumentError, "can't get const #{path}: #{e}" end end end end |