Module: ROM::AutoCurry

Defined in:
lib/rom/support/auto_curry.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(klass) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
# File 'lib/rom/support/auto_curry.rb', line 3

def self.extended(klass)
  busy = false

  klass.define_singleton_method(:method_added) do |name|
    return if busy
    busy = true
    auto_curry(name)
    busy = false
    super(name)
  end
end

Instance Method Details

#auto_curry(name) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/rom/support/auto_curry.rb', line 15

def auto_curry(name)
  curried = self.curried
  meth = instance_method(name)
  arity = meth.arity

  define_method(name) do |*args|
    if arity < 0 || arity == args.size
      meth.bind(self).(*args)
    else
      curried.new(self, name: name, curry_args: args, arity: arity)
    end
  end
end