Skip to content

Instantly share code, notes, and snippets.

@benolee
Last active December 18, 2015 22:39
Show Gist options
  • Save benolee/5856200 to your computer and use it in GitHub Desktop.
Save benolee/5856200 to your computer and use it in GitHub Desktop.
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