Created
October 11, 2014 17:23
-
-
Save Mon-Ouie/e2f6036f4685cae70b64 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
def ap(*args, &block) | |
lambda do |recv, *new_args, &new_block| | |
recv.send(*(args + new_args), &(block || new_block)) | |
end | |
end | |
class Object | |
def try_it(*arguments, &block) | |
puts "Called try_it on #{inspect} with #{arguments.inspect} and " + | |
"block: #{block.inspect}" | |
end | |
end | |
puts [{"foo" => "bar"}, {"foo" => "baz"}].map(&ap(:[], "foo")) | |
a = proc {} | |
b = proc {} | |
ap(:try_it, "foo").call 1 | |
ap(:try_it, "foo").call 1, "bar" | |
ap(:try_it).call 1 | |
ap(:try_it).call 1, "bar" | |
ap(:try_it, "foo", &a).call 1, "bar" | |
ap(:try_it, "foo").call(1, "bar", &b) | |
ap(:try_it, "foo", &a).call(1, "bar", &b) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment