Module: ConstructorShortcut::Cache
- Defined in:
- lib/constructor_shortcut/cache.rb
Class Method Summary collapse
Class Method Details
.resolve(name, class_name) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/constructor_shortcut/cache.rb', line 4 def self.resolve(name, class_name) @cache ||= {} key = "#{name.inspect}, #{class_name.inspect}".freeze @cache[key] ||= Module.new do @key = key class << self def name "ConstructorShortcut[#{@key}]" end alias_method :to_s, :name alias_method :to_str, :name alias_method :inspect, :name end define_method class_name do |*args, &block| new(*args, &block).public_send(name) end end end |