From: Austin Ziegler Date: 2002-12-14T14:27:22+09:00 Subject: Re: [RCR] Global Regexp Match Mechanism (//g) On Sat, 14 Dec 2002 12:45:21 +0900, nobu.nokada@softhome.net wrote: > Hi, > > At Sat, 14 Dec 2002 11:53:20 +0900, > Austin Ziegler wrote: >> Okay; since 90% of what we need is present, why not add a new >> method to Regexp, #gmatch(str, pos = nil, flags = nil). Adding >> pos to #match seems a poor fit because of the flags argument >> already present. > Regexp#match in present takes only str. Sorry, I was confusing #match and ::new (: You're right. #gmatch isn't necessary. >> Also, if a MatchData is passed as str, it should implicitly >> call MatchData#end for pos unless pos is non-nil. IMO, being >> explicit about doing a //g-type match is a Good Thing. > MatchData as String? Well, in such case I'd expect matching > to $&(equals $~.to_s). Actually, I was thinking something like: def gmatch(str, pos = nil) if str.class == MatchData if pos.nil? match(str.string, str.end(0)) else match(str.string, pos) end else match(str, pos) end end I understand that checking the class is considered a bad thing, so this should be viewed as a model, only. -austin -- Austin Ziegler, austin@halostatue.ca on 2002.12.14 at 00.19.50