module ConstructorShortcut
Generates anonymous module containing single class method
rubocop:disable Metrics/MethodLength, Style/Documentation
Constants
- VERSION
Public Class Methods
[](name = :call, class_name = :call)
click to toggle source
Used to set method name
# File lib/constructor_shortcut.rb, line 9 def self.[](name = :call, class_name = :call) @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
name()
click to toggle source
# File lib/constructor_shortcut.rb, line 18 def name "ConstructorShortcut[#{@key}]" end
Public Instance Methods
call(*args, &block)
click to toggle source
# File lib/constructor_shortcut.rb, line 32 def call(*args, &block) new(*args, &block).call end