Last active
November 22, 2016 09:46
-
-
Save cutalion/17c91699ad00457bf44f8b22c4c54ab9 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
class SuperCurry | |
def call(a, b) | |
puts "#{a} + #{b} = #{a + b}" | |
end | |
def curry(*args) | |
arity = method(:call).arity | |
curried_args = args | |
if curried_args.size == arity | |
call(*curried_args) | |
else | |
-> (*args) { curry *(curried_args + args) } | |
end | |
end | |
end | |
s = SuperCurry.new | |
c = s.curry | |
c.call(1).call(2) #=> 1 + 2 = 3 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment