Skip to content

Instantly share code, notes, and snippets.

@nakajima
Created July 22, 2008 15:26
Show Gist options
  • Save nakajima/1075 to your computer and use it in GitHub Desktop.
Save nakajima/1075 to your computer and use it in GitHub Desktop.
A version of Object#try that allows arguments and a block
class Object
def try(method, *args, &block)
respond_to?(method) ? send(method, *args, &block) : nil
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment