Created
January 16, 2009 23:57
-
-
Save evanphx/48215 to your computer and use it in GitHub Desktop.
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
class TrySink | |
def initialize(obj) | |
@object = obj | |
end | |
undef class | |
def method_missing(meth, *a) | |
if @object.respond_to? meth | |
@object.__send__ meth, *a | |
else | |
nil | |
end | |
end | |
end | |
class Object | |
def try | |
TrySink.new(self) | |
end | |
end | |
a = [] | |
p a.try.class | |
p a.try.crap | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment