In article <Pine.LNX.4.30.0205182039210.25793-100000 / candle.superlink.net>, David Alan Black <dblack / candle.superlink.net> wrote: > Hello -- > > On Sun, 19 May 2002, Michael Campbell wrote: > > > > Look on the bright side: > > > > > > str = gets > > > matched, x, y = str.match /^\s*(\S+)\s+(\S+)\s*$/ > > > if matched > > > puts "You typed the words #{x} and #{y}." > > > else > > > puts "You didn't type two separate words." > > > end > > > > > > and such. The MatchData object really isn't such a bad thing :-) > > > > No more "bad thing" than necessary though. > > > > YOu could just as easily check "x" or "y" instead of "matched" in > > your above snippet. > > > > I'm probably in the minority and I'm ok with that, but #match > > matching n things but returning n+1 values breaks MY worldview of > > "least astonishment". > > Remember though: what's really being matched is the whole pattern, > while the ()-captures are really just submatches. So #match is really > matching 1 thing (the pattern), plus returning meta-information about > n sub-things. Which can be thought of as [$&, $1, $2, $3, etc...]