From: David Alan Black Date: 2000-12-23T14:03:02+09:00 Subject: [ruby-talk:7991] Re: Naming of "defined?" On Sat, 23 Dec 2000, craig duncan wrote: > I made a mistake in thinking there was something wrong with the `not > defined?' predicate in: > > craig@duncan:/usr/home/craig/ruby$ cat t.rb > #!/usr/bin/ruby Use the -w flag -- that way if matz introduces new warnings, you'll be able to see them :-) > 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" But note what happens if you put parens after that last i: .... p defined? i() output: "method" "method" Here's a few more little test lines, in irb: irb 1> def i irb 2> "method i" irb 3> end ==>nil irb 4> public :i ==>Object irb 5> i = 123 ==>123 irb 6> self.i ==>"method i" irb 7> i ==>123 irb 8> defined? self.i ==>"method" irb 9> defined? i ==>"local-variable" So the local variable i masks, but does not actually replace, the method i (as I understand it). David -- David Alan Black home: dblack@candle.superlink.net work: blackdav@shu.edu Web: http://pirate.shu.edu/~blackdav