From: James Edward Gray II Date: 2005-09-26T06:42:09+09:00 Subject: Re: String#ggsub On Sep 25, 2005, at 3:25 PM, Gavin Kistner wrote: > I occasionally find myself with gsub regexp that either eat too > much, or work within a nesting, such that I need to run gsub more > than once in order to get the desired end result. The code I end up > writing tends to be of the form: > > while foo.gsub!( /.../, ... ); end > > Frankly, I really don't like that. It's like JS people who write > things like: > for ( var walkerNode = this; walkerNode.parent; walkerNode = > walkerNode.parent ){} > 'abusing' the for loop construct to hold their logic. > > Is there some other form in Ruby of "keep doing this until it > returns nil" that is less...gross? Of course, it's trivial to roll one up: #!/usr/local/bin/ruby -w module Kernel def complete loop { break unless yield } end end if __FILE__ == $0 digits = "3211" complete { digits.gsub!(/(\d)\1+/) { |d| d[0, 1].to_i + 1 } } p digits # => "4" end __END__ Though I do realize that's not what you asked. James Edward Gray II