From: Eleanor McHugh Date: 2007-04-04T19:36:00+09:00 Subject: Re: Everything is a object? On 4 Apr 2007, at 11:02, Jamal Soueidan wrote: > I have been reading about these various boolean returns, how Ruby look > at them, as you mentioned false and nil is the only objects which are > considered false. > > But I thought you did not need to define/declare any variables before > using it, but this has been misunderstood, you should somehow > assign the > variable to something before trying to use it, since Ruby "Still" > don't > know what object it is, right? The point is that you don't have to define a variable before you make an assignment to it, much like in older variants of BASIC. Assignment implicitly declares the variable to exist within the specified scope. However until you make an assignment the interpreter is not aware of the variable's existence (because logically it does not yet exist) and so attempts to reference it will fail to produce a reference to an object. An attempt will also be made to apply the token to the current object as a method, and if this too fails then the interpreter has no choice but to flag an error condition because semantically your program is broken - it makes no sense. When you use defined? all you are essentially doing is asking the interpreter whether or not the given token references an object within the current scope. Whilst the interpreter could be implemented in such a way that every unknown token returned a nil object if it was unknown to the interpreter, this would break the principle of least surprise. Think of this as equivalent to NaN (not a number) in standard floating- point libraries. Ellie Eleanor McHugh Games With Brains ---- raise ArgumentError unless @reality.responds_to? :reason