Sha256: 9fa7feb325426e046a2fcb5076229b6a4df56b3e42f9c809448c4f933e3fc516
Contents?: true
Size: 614 Bytes
Versions: 2
Compression:
Stored size: 614 Bytes
Contents
module Dependor class ClassNameResolver attr_reader :search_modules def initialize(search_modules) @search_modules = search_modules end def for_name(name) class_name = camelize(name) modules = search_modules + [Object] klass = nil modules.each do |mod| klass = mod.const_get(class_name) rescue nil break if klass end klass end private def camelize(symbol) string = symbol.to_s string = string.gsub(/_\w/) { |match| match[1].upcase } return string.gsub(/^\w/) { |match| match.upcase } end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
dependor-1.0.1 | lib/dependor/class_name_resolver.rb |
dependor-1.0.0 | lib/dependor/class_name_resolver.rb |