From: Devin Mullins Date: 2007-04-04T11:37:13+09:00 Subject: Re: Everything is a object? Jamal Soueidan wrote: > so in Ruby everything is object if it was declared before :P o I think perhaps the more accurate, though less sexy, wording is "every expression that returns returns an object."* For example: 'rescue' is not an object, it's a keyword. 'begin..rescue..end' is an expression, and hence has a return value, and that return value is an object. In your case: 'as_yet_undefined_variable' is an expression, too. In the case of a bare word, Ruby's built-in behavior is to: 1) check for a local variable binding 2) failing that, send a message to self #1 is failing, so it sends the as_yet_undefined_variable message to self. If the method were defined, it would invoke it. Since it's not defined, it calls method_missing on self. This is all built-in, unoverrideable behavior (AFAIK). The default implementation of method_missing (which you *can* override) raises a NoMethodError exception. The exception is an object, but the act of "raising" it triggers some built-in behavior to fail fast. This is why I say "every expression that returns" instead of "every expression". This is one case of an expression that doesn't return. This is all more complicated than the cute "Everything is an object," but it's also far more useful, and in my opinion, pretty intuitive.** I Might Be Wrong. Of course, I'm guessing Gary's email is more useful to you, but I don't know PHP, and I'm a pedant. Also, if you find yourself using defined? more than once a year, you might wanna post some code to ruby-talk for constructive criticism.*** Devin * Lowercase 'o' intentional -- IIRC, evil.rb allows you to skirt the Object superclass thing. ** One exception being that you can't always say `puts a unless (a = some_method).nil?`. (Note the single equals sign, vice double.) *** I'm including you, Rails Core!