Class: Proc
- Inherits:
-
Object
- Object
- Proc
- Defined in:
- lib/curry.rb
Instance Method Summary collapse
Instance Method Details
#*(g) ⇒ Object
2 3 4 5 6 7 8 9 |
# File 'lib/curry.rb', line 2 def * g if g.arity == 0 lambda { self.call(g.call) } else vars = (1..(g.arity)).map{|num| "var_#{num}"}.join(",") eval "lambda {|#{vars}| self.call(g.call(#{vars})) }" end end |
#<<(*args) ⇒ Object
22 23 24 |
# File 'lib/curry.rb', line 22 def <<(*args) self.[](*args) end |
#[](*args) ⇒ Object
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/curry.rb', line 11 def [](*args) diff = self.arity - args.size # do this? or throw an error on diff < 0 ? if diff <= 0 self.call(*args) else vars = (1..diff).map{|num| "var_#{num}"}.join(",") eval "lambda {|#{vars}| self.call(*(args + [#{vars}])) }" end end |