From: Gennady Date: 2003-05-07T06:45:09+09:00 Subject: Re: Testing for a class existence ----- Original Message ----- From: "Brian Candler" To: "ruby-talk ML" Sent: Tuesday, May 06, 2003 2:35 PM Subject: Re: Testing for a class existence > On Wed, May 07, 2003 at 06:23:06AM +0900, Gennady wrote: > > In both cases Ruby parses Aaa::Bbb::Ccc before calling a method and is expected to complain. > > So, is "defined?" an operator then? I am too lazy today to look into the source. > > You can always look in the Pickaxe :-) Yes, it's an operator: > > Ruby supports all the standard boolean operators and introduces the > new operator defined?. > ... > The defined? operator returns nil if its argument (which can be an Interesting. In my Pickaxe hardcopy it says "The defined? method returns nil if ..." and "... the new predicate method defined?." a little bit earlier. Must be some typo. > arbitrary expression) is not defined, otherwise it returns a > description of that argument. If the argument is yield, defined? > returns the string `yield'' if a code block is associated with the > current context. > > defined? 1 � "expression" > defined? dummy � nil > defined? printf � "method" > defined? String � "constant" > defined? $& � nil > defined? $_ � "global-variable" > defined? Math::PI � "constant" > defined? ( c,d = 1,2 ) � "assignment" > defined? 42.abs � "method" > > http://www.rubycentral.com/book/tut_expressions.html > (although I keep a local copy for easy grepability :-) > > Regards, > > Brian. > >