Last active
August 29, 2015 14:13
-
-
Save padde/b706f851f00e84ffd7de to your computer and use it in GitHub Desktop.
Proc#with – 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
require 'forwardable' | |
class Proc | |
def with(*arguments, &block) | |
proc do |*remaining_arguments| | |
call(*remaining_arguments, *arguments, &block) | |
end | |
end | |
end | |
class Method | |
extend Forwardable | |
def_delegator :to_proc, :with | |
end | |
class Symbol | |
extend Forwardable | |
def_delegator :to_proc, :with | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage with
Proc
is a bit like "reverse currying"The other methods are just convenience wrappers for
Symbol
and
Method
objects