From: ptkwt@...1.aracnet.com (Phil Tomson) Date: 2003-05-07T07:52:45+09:00 Subject: Re: Testing for a class existence In article <20030506213500.GA49605@uk.tiscali.com>, Brian Candler wrote: >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 > 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" This one ^^^^^^^^^^^^^^^^ doesn't seem to work under 1.8: irb(main):002:0> defined?(c,d = 1,2) SyntaxError: compile error (irb):2: syntax error defined?(c,d = 1,2) > defined? 42.abs � "method" > It's interesting, I always thought defined? returned true or false, but it returns a String (if the argument has been defined) or nil (if it hasn't). ....you learn something new everyday (or should anyway). Phil