From: Florian Odronitz Date: 2010-07-30T17:53:27+09:00 Subject: Re: Accessing object in rescue block Thanks for your thoughts, I figured it out. I was coming from this Article: http://rbjl.net/26-the-28-bytes-of-ruby-joy The author suggests to let the method_missing of Nil always return nil so you could do things like: some_object.this_is_null.do_something_more would return nil and not raise on the undefined method 'do_something_more' on nil. I thought such an approach was to intrusive and it would be better to do something like: ignore_nil{some_object.this_is_null.do_something_more} My current implementation looks like this: class NoMethodErrorInNil < NoMethodError; end class NilClass def method_missing(method_name, *args) raise NoMethodErrorInNil, "undefined method `#{method_name}' for nil:NilClass" end end class Object def ignore_nil(return_value = nil, &block) begin yield rescue NoMethodErrorInNil => e return return_value end end end -- Posted via http://www.ruby-forum.com/.