Module: ConstructorShortcut

Defined in:
lib/constructor_shortcut.rb,
lib/constructor_shortcut/cache.rb,
lib/constructor_shortcut/version.rb

Overview

rubocop:disable Metrics/MethodLength, Style/Documentation

Defined Under Namespace

Modules: Cache

Constant Summary collapse

VERSION =
"0.6.0".freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.[](name = :call, class_name = :call) ⇒ Object

Used to set method name



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# 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

Instance Method Details

#call(*args, &block) ⇒ Object



32
33
34
# File 'lib/constructor_shortcut.rb', line 32

def call(*args, &block)
  new(*args, &block).call
end