From: David Alan Black Date: 2001-11-18T05:03:53+09:00 Subject: [ruby-talk:25726] Re: String#match Hello -- On Sun, 18 Nov 2001, James F. Hranicky wrote: > > Anyone up for String#match? I can't say I've been pining away for it :-) > foo = "foo bar baz" > > class << foo > > def match(re) > > if (md = re.match(self)) > a = md.to_a > a.shift > return a.empty? ? 1 : a > else > return nil > end > end > end > > arr = foo.match(/(bar).*(baz)/) > p arr if arr It seems more logical for a match method to return MatchData: class String; def match(re); re.match(self); end; end then let the caller decide how to break it out. (Of course, then one might as well just type them the other way around in the first place :-) David -- David Alan Black home: dblack@candle.superlink.net work: blackdav@shu.edu Web: http://pirate.shu.edu/~blackdav