"Randy Lawrence" <jm / zzzzzzzzzzzz.com> schrieb im Newsbeitrag news:fqlHc.1176$%_.703 / newssvr32.news.prodigy.com... > Kirk Haines wrote: > > On Fri, 9 Jul 2004 01:21:29 +0900, Kirk Haines wrote > > > > > >>My Ruby-fu is failing me at coming up with a relatively concise yet > >>readable way to do this in Ruby. My implementation is, I am sure, > >>much longer than necessary. > >> > >>So, anyone have any ideas? How would you do this? > > > > > > And....nevermind. I figured out where I was being thick. gsub with a block > > works nicely. > > > > > > Kirk Haines > > > > > > > > We ran into the same question earlier today. Maybe the documentation > for String.sub() should mention String.gsub(). Good point. > I think it would have > been more intuitive to have an optional parameter to sub() for > global/case-insenstive/etc. Case sensitivity is controlled by a regular expression flag. About gsub vs. sub with a paramter that controls global replacement: while that might mimic what vi does, it's generally considered better style to have separate methods if behavior differs than to have a single method whose behavior is controlled by flags. Also it's more efficient, too. Kind regards robert