From: Austin Ziegler Date: 2005-08-13T00:23:43+09:00 Subject: Re: Re-reading a portion of a source file from a specific point On 8/12/05, daz wrote: > Daniel Berger wrote: > > From within a Ruby program, is there a way to get Ruby to re-read itself > > from a specific part of the file? > > [...] > > I thought perhaps there were some tricks I could > > use with __DATA__, __END__ or __FILE__, but I wasn't sure. > The DATA constant initially points after the __END__ marker. > The origin of the DATA IO object is the script itself ! > > # Line 1 > DATA.rewind > script = DATA.readlines > p script[1..2] > __END__ > > #-> ["DATA.rewind\n", "script = DATA.readlines\n"] This only works for the top-level script ($0). It does not work for included scripts, the way that Perl's __END__ and DATA markers do. -austin -- Austin Ziegler * halostatue@gmail.com * Alternate: austin@halostatue.ca