Created
July 22, 2008 15:32
-
-
Save nakajima/1084 to your computer and use it in GitHub Desktop.
Curry args on a proc. Probably buggy.
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 Proc | |
| def curry(*arguments) | |
| if arguments.empty? | |
| return self | |
| else | |
| _proc = self.dup | |
| return lambda do |*args| | |
| return _proc.call(*arguments.concat(args)) | |
| end | |
| end | |
| end | |
| end | |
| a = proc { |name, age| puts "#{name} is #{age}" } | |
| b = a.curry('Pat') | |
| b.call(22) # => Pat is 22 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment