From: Tom Cloyd Date: 2008-03-15T16:18:34+09:00 Subject: Re: how to abruptly end a program? Joel VanderWerf wrote: > Tom Cloyd wrote: >> Joel VanderWerf wrote: >>> Tom Cloyd wrote: >>>> I read in (p. 303) - ""If Ruby comes >>>> across a line anywhere in the source containing just �_ _END_ _�, >>>> with no leading or trailing whitespace, it treats that line as the >>>> end of the program�any subsequent lines will not be treated as >>>> program code." >>>> >>>> That's not what's happening for me. The following - >>>> _ _END_ _ >>>> __END__ >>>> _END_ >>>> >>>> all produce the same result for me - "undefined local variable or >>>> method" >>>> That DOES bring the program to an abrupt end, but its rather >>>> ungraceful. Is this the intended result - a crash due to an >>>> interpreter error? >>> >>> What the quote (a bit ambiguous perhaps) means is that the __END__ >>> line and following lines are not treated as part of the program >>> text. It has nothing to do with control flow. It's like comment >>> block that runs to the end of the file without any explicit >>> termination. (It's more than that because you can read it with DATA.) >>> >> OK, but couldn't ANY uninitialized variable achieve the same messy >> result? What's the point? This surely can't be the intended result. >> Makes no sense to me. > > __END__ by itself on a line shouldn't exit the program. If you're > getting that error, maybe there is an extra char on the line. A space > perhaps? > Yes, that would explain it, but I made sure this problem didn't occur from the beginning, which is one reason I'm puzzled. I really don't see anything wrong with what I'm feeding the interpreter. So, I did a different test program - require 'readline' puts "test under way\ninput var: " #opt = readline( "=--> \n") opt = gets.chomp puts( opt) __END__ puts( opt) result: test under way input var: 5 5 Here, we don't get an error. We just get ignored. This is nuts. t. -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Tom Cloyd, MS MA, LMHC Private practice Psychotherapist Bellingham, Washington, U.S.A: (360) 920-1226 << tc@tomcloyd.com >> (email) << TomCloyd.com >> (website & psychotherapy weblog) << sleightmind.wordpress.com >> (mental health issues weblog) << directpathdesign.com >> (web site design & consultation) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~