From: Robert Klemme Date: 2009-08-06T23:45:03+09:00 Subject: Re: remove commas from string 2009/8/6 Nick Brown : > Ruby has the neat ability to pass a block to gsub. This can be a more > versatile solution than using backreferences. It isn't needed though in this case. Please also note that the block form is usually slower. The block form is most appropriate if you need to calculate each replacement individually. > It also allows Jason to > use his original, straight-forward regex. The matched string is passed > to the block, and whatever the block evaluates to is used as the > replacement string. Check it out: > > irb(main):012:0> s > => "B747-400, 8357 miles, 561 mph, 4 Pratt & Whitney PW 4056 turbofans, > turbofans, 56,000 lbs." > irb(main):013:0> s.gsub(/\d+,\d+/) { |subs| subs.gsub(',', '') } > => "B747-400, 8357 miles, 561 mph, 4 Pratt & Whitney PW 4056 turbofans, > turbofans, 56000 lbs." Frankly, I'd rather use any of the other non block solutions that the one with a block. My 0.02EUR. Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/