From: Trans Date: 2005-11-24T02:22:25+09:00 Subject: Re: String#to_rx ? Austin Ziegler wrote: > I disagree that either #to_re or #to_rx would be a good name for this > construct. I think that it would be better to have a method on Regexp > itself (a new, alternative constructor) that does this. Maybe: > > Regexp.compile_escaped(str) The problem here is largely one of brevity. Who wants to type all that when #to_re will do? > I don't think I've actually ever seen Regexp.compile used, so maybe it > can be repurposed in 1.9 to do this. > > FWIW, I don't tend to use the construct that Alex did -- I tend to > either anchor my strings or insert them in the middle of a larger > regexp, which is why I don't particularly think that this is a method > that belongs on String. > If it's to be on String, though, it should probably be on a few others > as well (Fixnum) and it should be explicit: #to_regexp. #to_regexp would imply that the object was some type of Regexp already. #to_re or #to_rx clearly indicate it is a conversion. It's a pretty innocent method and I don't think it is too much trouble to have even if it's not the most useful method in the world. I think even more usful though would just be a method on String that does the Regexp escaping. I had been using my own small Kernel method #resc(str) for this, but now I see it would be much more useful as a String method: /^#{foo.resc}/ =~ bar All things being the same, I'll put that in the next verison of Facets. T.