Skip to content

Instantly share code, notes, and snippets.

@jamuc
Created April 10, 2014 08:40
Show Gist options
  • Save jamuc/10357305 to your computer and use it in GitHub Desktop.
Save jamuc/10357305 to your computer and use it in GitHub Desktop.
Monkey Patch the Ruby Object
# Monkey patch ruby Object with try method.
# Inspiration Rails.
# http://api.rubyonrails.org/classes/Object.html#method-i-try
class Object
def try(*a, &b)
if a.empty? && block_given?
yield self
else
publice_send(*a, &b) if respond_to?(a.first)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment