On Thu, Aug 09, 2001 at 02:50:00PM +0100, ruby-talk / ruby-lang.org wrote:
> Hello --
> 
> On Thu, 9 Aug 2001, Dave Thomas wrote:
> 
> > Renald Buter <buter / CWTS.LeidenUniv.nl> writes:
> >
> > > Looking back at my question, I see it is a bit fuzzy. What I am
> > > really looking for is a case-like structure _with_ fall-through, but
> > > _without_ having to write down the variable name for each regexp
> > > test.
> >
> > Possibly the Ruby case statement might help :)
> >
> >   case bla
> >   when /help/ then help
> >   when /exit/ then exit
> >   else
> >     puts "Sorry"
> >   end
> >
> > And not a $_ in sight.
> 
> I think Renald wanted the possibility of more than one statement
> executing.  In his Perl-esque example:
> 
> >        bla = "help_more"
> >        for bla
> >                # $_ is now equal to bla ("help_more")
> >                /help/ and help
> >                /help_more/ and help_more
> >                /help_even_more/ and help_even_more
> >        end
> 
> help and help_more would both happen.
> 
> One possibility would be:
> 
>   for $_ in bla
>     help if /help/
>     help_more if /help_more/
>     help_even_more if /help_even_more/
>   end
> 

Ah. I see. I hadn't thought of this one. Thank you. 
It gives me the behaviour I was looking for, but unfortunately, it
destroys the previous value of $_

	foo = "abcdefg"
	puts $_
	for $_ in foo
		puts $& if /abc/
		puts $& if /def/
	end
	puts $_

results in:

	% ruby src/test.rb
	nil
	abc
	def
	abcdefg

But I can live with that :)

> 
> Any chance that some other form of method dispatch would be
> cleaner/safer?  (But that's another matter.)
> 

I don't know if you were asking me, but the method-dispatch example
was a bit conjured up for this particular question.

Thanks again,

Renald