From: Matthew Kerwin Date: 2013-02-12T06:28:59+09:00 Subject: Re: elegant way to determine if something is defined sto.mar wrote in post #1096319: > Hmmm... very dangerous. > > That would catch all kinds of exceptions, not only the NameError: > > a = [] > b = a + 1 > # => TypeError: can't convert Fixnum into Array > > vs. > > a = [] > b = a + 1 rescue 99 > b # => 99 Back in the olden days, MOO code had the following: `x + 1 ! E_TYPE'; ... returns (x+1) or E_TYPE, or raises E_VARNF. `x.y ! E_PROPNF, E_PERM => 17' ... returns x.y if x is an object and x.y is a readable property; returns 17 if x is an object but x.y is not defined or not readable; or raises something else (like E_VARNF or E_INVIND) `1 / 0 ! ANY'; ... returns E_DIV I liked being able to explicitly trap a certain class of exception, and either return the exception itself or a default value. Additionally it had try/catch blocks. [1] http://files.moo.ca/1/1/7/ProgrammersManual_26.html#SEC26 -- Posted via http://www.ruby-forum.com/.