Module: ConstructorShortcut
- Defined in:
- lib/constructor_shortcut.rb,
lib/constructor_shortcut/version.rb
Overview
Generates anonymous module containing single class method
Constant Summary collapse
- VERSION =
"0.4.0".freeze
Class Method Summary collapse
-
.[](name = :call, class_name = :call) ⇒ Object
Used to set method name rubocop:disable Metrics/MethodLength.
Class Method Details
.[](name = :call, class_name = :call) ⇒ Object
Used to set method name rubocop:disable Metrics/MethodLength
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/constructor_shortcut.rb', line 7 def self.[](name = :call, class_name = :call) @cache ||= {} @cache[name] ||= Module.new do @key = name.inspect 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 |