Hi --

On Sun, 19 May 2002, Dossy wrote:

> According to David Black about Ruby 1.7, String#match returns an
> array not only with the matched strings, but it basically returns
> $~, so you'd have to do:
>
>   junk, x, y = "foo bar".match /(foo) (bar)/
>
> Which is annoying, but will suffice.

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 :-)


David

-- 
David Alan Black
home: dblack / candle.superlink.net
work: blackdav / shu.edu
Web:  http://pirate.shu.edu/~blackdav