Last active
December 18, 2015 22:39
-
-
Save benolee/5856200 to your computer and use it in GitHub Desktop.
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
class UnboundMethod | |
def self.new(name = :'', &block) | |
Module.new.module_eval do | |
define_method(name, block) | |
instance_method(name) | |
end | |
end | |
def call(receiver, *args, &block) | |
bind(receiver).call(*args, &block) | |
end | |
end | |
class Method | |
def self.new(receiver, name = :'', &block) | |
UnboundMethod.new(name, &block).bind(receiver) | |
end | |
def curry(arity = arity()) | |
Method.new(receiver, &to_proc.curry(arity)) | |
end | |
end | |
class Proc | |
def bind(receiver) | |
Method.new(receiver, &self).to_proc | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment