Class: ROM::AutoCurry::Wrapper Private

Inherits:
Module
  • Object
show all
Defined in:
lib/rom/auto_curry.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Instance Method Summary collapse

Constructor Details

#initialize(name, arity, &block) ⇒ Wrapper

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Wrapper.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/rom/auto_curry.rb', line 10

def initialize(name, arity, &block)
  define_method(name) do |*args, **kwargs, &mblock|
    kwargs_size =
      if kwargs.empty?
        0
      else
        1
      end

    response =
      if arity.negative? || arity.eql?(args.size + kwargs_size)
        super(*args, **kwargs, &mblock)
      else
        self.class.curried.new(self, view: name, curry_args: args, arity: arity)
      end

    if block
      response.instance_exec(&block)
    else
      response
    end
  end
end