Module: Funkify::ClassMethods

Defined in:
lib/funkify.rb

Instance Method Summary collapse

Instance Method Details

#auto_curry(*names) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/funkify.rb', line 45

def auto_curry(*names)
  if names.empty?
    in_use = nil
    define_singleton_method(:method_added) do |name|
      return if in_use
      in_use = true
      auto_curry name
      in_use = false
    end
    return
  end

  names.each do |name|
    m = instance_method(name)
    curried_method = nil
    define_method(name) do |*args|
      curried_method ||= m.bind(self).to_proc.curry
      curried_method[*args]
    end
  end
end