Created
April 10, 2014 08:40
-
-
Save jamuc/10357305 to your computer and use it in GitHub Desktop.
Monkey Patch the Ruby Object
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
# 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