Skip to content

Instantly share code, notes, and snippets.

@Mon-Ouie
Created July 6, 2013 07:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Mon-Ouie/5938976 to your computer and use it in GitHub Desktop.
Save Mon-Ouie/5938976 to your computer and use it in GitHub Desktop.
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