From: Hugh Sasse Staff Elec Eng Date: 2003-09-11T19:20:02+09:00 Subject: Re: What *are* variables? Which are nil now? On Thu, 11 Sep 2003, Robert Klemme wrote: > > "Hugh Sasse Staff Elec Eng" schrieb im Newsbeitrag > news:Pine.GSO.4.53.0309101847560.23363@neelix... > > gives some line numbers with an each keyword, where the code looks like > > raise "@b1 is nil" if @b1.nil > > @b1.each { |bf| > > so I know that @b1 is not nil when it gets here. The each method is > > one I wrote, so I'd expect it to blow up in there, with an > > associated line number. > > There are two issues with the line "raise "@b1 is nil" if @b1.nil?": > > 1. The test is inappropriate, what you really want is to ensure that the This was debugging code, added after getting the error. I wanted to be sure that the @b1 was the thing that was becoming nil. It wasn't > obj referred to by @b has method "each". So these are better alternatives > (but see issue 2): > > raise "Wrong @b1" unless @b1.kind_of? Enumerable > raise "Wrong @b1" unless @b1.respond_to? :each Those would avoid an "undefined method" error, which was not what I was getting. They are right for checking each though I was getting "\n#" > > 2. Btw, generally it's superfluous to include the explicite test and raise Yes, it was not in the original program. > > > Can I get ruby to tell me all things that point at the one Nil > > object in the universe, at the present time? > > Well, you could do this > [ p @b1 # prints info about @b1 etc] > or use the debugger. Yes, that produced the same message in some very odd places, but no variables showed up with the error because it was in the middle of an expression. > > But as I said before, generally this is not a too good idea. > > Regards > > robert Thank you, Hugh