Skip to content

Instantly share code, notes, and snippets.

@fogus
Forked from headius/partial_application.rb
Created September 18, 2011 22:40
Show Gist options
  • Save fogus/1225651 to your computer and use it in GitHub Desktop.
Save fogus/1225651 to your computer and use it in GitHub Desktop.
Partial application that works on all Ruby implementations
class Object
def _(name, *partial_args)
Proc.new do |*new_args|
send name, *partial_args.map {|arg| arg == :_ ? new_args.shift : arg}
end
end
end
# Practical examples:
[1,2,3].each &_(:puts, :_)
#=> 1\n2\n3\n
[:send, :puts].select &'foo'._(:respond_to?, :_, false)
#=> [:send]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment