Adding a flag to change method behavior is usually regarded bad OO practice.
The usual solution is to have two different methods - one for each behavior.
That increases modularity, simplifies the implementation and improves
performance.
I'd rather have String#gsub_md, String#gsub_md! and String#scan_md than the
flag although I have to admit that those method names are ugly.
[Note: I'm continuing the discussion here, because RCR276 seems to
have some data disappearing on a regular basis. David, if you're
generating rdiffs for the Wiki discussion, it might be nice if you
could send me a .tar.gz of the rdiff associated with RCR276 so that I
can see if my changes are making it in the first place.]
I agree that the presence of the flag may not be ideal, but note that
#gsub already uses such conditional work -- and not having the flag
would actually cause unnecessary code duplication (per the C code
above). Right now, it accepts #gsub(patt, repl) or #gsub(patt, repl) {
repl-block }; this would extend the capability to include #gsub(patt,
repl-type) { repl-block }, the repl-type determining what is yielded.
Again: this is entirely about the yielded value. I believe that all
forms are correct for how they work when they don't use a block.
The idea of having #gsub with the flag (as opposed to the #gsubm [the
name I had chosen instead of #gsub_md) form which I rejected in
writing my response to Nobu) is that IMO we should encourage the use
of the new form with MatchData objects, not the other form. By using
#gsubm, we discourage the use of the new form in favour of the old
form. The only way that I think that this would really work is to have
#gsub yield MatchData and #gsubs yield Strings, if we take that
approach. --AustinZiegler