Skip to content

Instantly share code, notes, and snippets.

@rickw
Created May 12, 2009 14:48
Show Gist options
  • Save rickw/110522 to your computer and use it in GitHub Desktop.
Save rickw/110522 to your computer and use it in GitHub Desktop.
A different way to "try"
#
# method messing try a different way
#
class Object
def try
Try.new self
end
end
class Try
def initialize(scope_obj)
@obj = scope_obj
end
def method_missing(meth, *args, &block)
return @obj unless @obj.respond_to? meth
@obj.send meth, *args, &block
end
end
class Fred
def me
yield
"I am!"
end
end
f = Fred.new
puts f.try.you
puts f.try.me { puts "yay!" }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment