From: gga Date: 2007-06-05T13:55:04+09:00 Subject: Re: Ruby problem with conditional ranges On Jun 4, 9:51 pm, "Todd A. Jacobs" wrote: > On Mon, Jun 04, 2007 at 04:35:25PM +0900, come wrote: > > prints up to "four" when (as I understand it) it should stop at "three" > since "## four" would make the if-statement false. Am I still missing > something obvious? > Yes. That will never work, as this is not Perl nor are you creating a range of regexp (which cannot be done, btw). See what happens when the match does happen as you want: irb> a = 'four' irb> (a =~ /two/)...(a =~ /four/) ArgumentError: bad value for range [result is: (nil...'four') ] Plus the uncommented # in the regex are probably making ruby assume a comment. This is another way of writing what you want to do: #!/usr/bin/ruby -w ## one ## two ## three ## four ## five File.open($0) do |file| range = [ '$_ =~ /^## two/', '$_ !~ /^## four/' ] while file.gets if eval("#{range[0]}") print $_.sub(/^## /, ''); range.shift end end end