Skip to content

Instantly share code, notes, and snippets.

@zimbatm
Created May 13, 2014 12:37
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 zimbatm/cf324970a9b368da3c4b to your computer and use it in GitHub Desktop.
Save zimbatm/cf324970a9b368da3c4b to your computer and use it in GitHub Desktop.
Useful little ruby extension
class Proc
def with_args(*args, &block)
proc do |obj|
call(obj, *args, &block)
end
end
end
class Symbol
def with_args(*args, &block)
proc do |obj|
obj.public_send(self, *args, &block)
end
end
end
if __FILE__ == $0
p [34, 55, 13].map(&:to_s.with_args(32))
case "foo"
when :respond_to?.with_args(:to_s) # Because Proc implements ===
puts "YES"
else
fail
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment