Sha256: 645e7864b8a3e84595576d7ccfb279f536639b39c7fba513b2ea606b57b935cc
Contents?: true
Size: 642 Bytes
Versions: 14
Compression:
Stored size: 642 Bytes
Contents
module Bogus class ConvertsNameToClass extend Takes class CanNotFindClass < RuntimeError; end takes :search_modules def convert(name) class_name = camelize(name) klass = nil @search_modules.each do |mod| klass = mod.const_get(class_name) rescue nil break if klass end raise CanNotFindClass.new("Can not locate class for name: #{name}") unless klass 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
14 entries across 14 versions & 1 rubygems