irb(main):001:0> /ab/+"cd" NameError: undefined method `+' for /ab/:Regexp from (irb):1 irb(main):002:0> class Regexp irb(main):003:1> def +(str) irb(main):004:2> Regexp.new(source + str) irb(main):005:2> end irb(main):006:1> end nil irb(main):007:0> /ab/+"cd" /abcd/ Seems reasonable. But then you would also want to test for a regex argument (and you can't just apply #to_s), and possibly other arguments. Is there a reason this doesn't already exist? William Djaja Tjokroaminata wrote: > Hi, > > I don't know whether it is worth an RFC (what is RFC?) > > At least, regarding the understanding, when you want to overload +=, it is > not for the source method, but for the regexp itself. "re.source" returns > a new string, which is independent of the re. Because a string accepts > the "+" operator, "re.source += str" returns another new string, but the > original re does not change. The correct way for your intention (when > it is overloaded) is to write "re += '|abc'". By the same token, you just > want a regexp to be able to accept the "+" operator (which is actually a > method). > > Regards, > > Bill > ============================================================================= > Berger, Daniel <djberge / qwest.com> wrote: > >>Good idea. What about overloading += for the source method? > > >>e.g. > > >>re = /xyz/ >>re.source += "|abc" >>puts re.source -> "xyz|abc" > > >>Worth an RFC? > > >>Regards, > > >>Dan > -- Joel VanderWerf California PATH, UC Berkeley mailto:vjoel / path.berkeley.edu Ph. (510) 231-9446 http://www.path.berkeley.edu FAX (510) 231-9512