Module: Tins::DeepConstGet
- Defined in:
- lib/tins/deep_const_get.rb
Class Method Summary collapse
-
.const_defined_in?(modul, constant) ⇒ Boolean
:nocov:.
- .deep_const_get(path, start_module = Object) ⇒ Object
Instance Method Summary collapse
Class Method Details
.const_defined_in?(modul, constant) ⇒ Boolean
:nocov:
6 7 8 |
# File 'lib/tins/deep_const_get.rb', line 6 def self.const_defined_in?(modul, constant) modul.const_defined?(constant) end |
.deep_const_get(path, start_module = Object) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/tins/deep_const_get.rb', line 16 def self.deep_const_get(path, start_module = Object) path.to_s.split('::').inject(start_module) do |p, c| case when c.empty? if start_module == Object Object else raise ArgumentError, "top level constants cannot be reached from"\ " start module #{start_module.inspect}" end when const_defined_in?(p, c) 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 |
Instance Method Details
#deep_const_get(path, start_module = Object) ⇒ Object
38 39 40 |
# File 'lib/tins/deep_const_get.rb', line 38 def deep_const_get(path, start_module = Object) ::Tins::DeepConstGet.deep_const_get(path, start_module) end |