From: hal9000@... Date: 2000-12-23T03:40:02+09:00 Subject: [ruby-talk:7974] Re: Naming of "defined?" See below... In article <3A4382EE.3C10B51E@nycap.rr.com>, craig duncan wrote: > Didn't i read that '?' at the end of a method name indicated a boolean > return value? > > defined? returns the symbol type, not a boolean. > > Therfore, this sort of confusion: > > craig@duncan:/usr/home/craig/ruby$ cat t.rb > #!/usr/bin/ruby > > def i > p "defining i as method" > end > p defined? i > > i = 0 if not defined? i > p defined? i > > craig@duncan:/usr/home/craig/ruby$ t.rb > "method" > "local-variable" > Disclaimer: I don't have a Ruby interpreter handy at the moment. What if i really is undefined? Doesn't it return false or nil? And really, that is adequate for a Boolean, there being no Boolean type as such in Ruby. The fact that it returns different meaningful values for truth could be viewed as just a bonus. Still, it's nice to know that you can distinguish in this way between a method name and a local variable... I've just never seen anyone do it as far as I can recall. Hal -- Hal Fulton Sent via Deja.com http://www.deja.com/