Last active
December 31, 2015 07:39
-
-
Save nicholasjhenry/7955658 to your computer and use it in GitHub Desktop.
Make a service class support currying, uh partial application?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Curryable | |
def curry(arity=nil) | |
method(:call).to_proc.curry(arity) | |
end | |
end | |
class Foo | |
include Curryable | |
def call(x, y, z) | |
x + y + z | |
end | |
end | |
f = Foo.new | |
ff = f.curry.(2, 3) # or f.curry[2, 3] | |
ff.(4) # or ff[4] => 9 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment