Module: Dotum::AutoloadConvention
- Included in:
- Dotum, AbstractRules, Rules, StandardOptions, Util
- Defined in:
- lib/dotum/autoload_convention.rb
Instance Method Summary collapse
-
#const_missing(sym) ⇒ Object
‘autoload` is dead, and we don’t want to deal with its removal in 2.0, so here’s a thread-unsafe poor man’s solution.
Instance Method Details
#const_missing(sym) ⇒ Object
‘autoload` is dead, and we don’t want to deal with its removal in 2.0, so here’s a thread-unsafe poor man’s solution.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/dotum/autoload_convention.rb', line 17 def const_missing(sym) full_sym = "#{name}::#{sym}" path_parts = full_sym.split("::").map { |part| part.gsub! /([^A-Z])([A-Z]+)/, "\\1_\\2" # OneTwo -> One_Two part.gsub! /([A-Z]+)([A-Z][^A-Z]+)/, "\\1_\\2" # ABCOne -> ABC_One part.downcase } require File.join(path_parts) # Make sure that we don't get stuck in an endless loop. `const_get` calls # into `const_missing`, so we can't use that. eval "defined?(#{full_sym}) ? #{full_sym} : super" end |