Since Regexp#match so far does not use a block, why not extend it to
iterate over all the (non-overlapping) matches in the string? I think
the following sums up what I mean:
···
class Regexp
def match(str)
if block_given?
str.gsub!(self) {|s| yield $~; s}
self
else
old_match(str) # the current Regexp#match
end
end
end
/<(.*?)>/.match(’’) {|m| puts m[1]}
…seems pretty intuitive to me.
Is this a bad idea?