Sha256: 170f4d16be1c0288320898a4f1f344fed1eec07957c442403a1a3558a2e546eb
Contents?: true
Size: 870 Bytes
Versions: 23
Compression:
Stored size: 870 Bytes
Contents
module Eco module API module Common module ClassHelpers def class_resolver(name, klass) define_singleton_method(name) { resolve_class(klass) } define_method(name) { self.class.resolve_class(klass) } end def resolve_class(klass, exception: true) @resolved ||= {} @resolved[klass] ||= case klass when Class klass when String begin Kernel.const_get(klass) rescue NameError => e raise e if exception end when Symbol resolve_class(self.send(klass)) else raise "Unknown class: #{klass}" if exception end end end end end end
Version data entries
23 entries across 23 versions & 1 rubygems