Sha256: 2e844485666ccfc43642e752078b264bd84b3fa107ed5134d49934e09427211e
Contents?: true
Size: 950 Bytes
Versions: 8
Compression:
Stored size: 950 Bytes
Contents
module Rake module Funnel module Support module InstantiateSymbol def self.included(klass) klass.extend(ClassMethods) klass.send(:instantiate, klass) end module ClassMethods attr_reader :module private def instantiate(mod) @module = mod end end private def create(sym, *args) return sym unless sym.is_a?(Symbol) found = [sym, sym.pascalize.to_sym] .select { |candidate| mod.constants.include?(candidate) } .first raise NameError, "Unknown type to instantiate: #{sym.inspect}. Available types are: #{available.inspect}" if found.nil? type = mod.const_get(found) type.new(*args) end def available mod.constants.sort end def mod self.class.module end end end end end
Version data entries
8 entries across 8 versions & 1 rubygems