From: Daniel Martin Date: 2007-01-13T01:32:00+09:00 Subject: Re: DRY gsub... Josselin writes: > I wrote the following ruby statements.. I get the result I need , I > tried to DRY it for 2 hours without being successfull , > > d = d.gsub(/\r\n/,' ') # get rid of carriage return > d = d.gsub(/;/,' ') # replace column by space > d = d.gsub(/,/,' ') # replace comma by space > a = d.split(' ') # split into component , space as divider > What's wrong with: a = d.split(/\r\n|[;, ]/) Or do you need d to be mangled as before? Although I probably would do something even shorter like this: a = d.split(/[;,\s]+/) However, for certain inputs that won't give exactly the same as your initial multi-step procedure. Also, any time you write: d = d.gsub(...) You're probably better off with: d.gsub!(...) -- s=%q( Daniel Martin -- martin@snowplow.org puts "s=%q(#{s})",s.map{|i|i}[1] ) puts "s=%q(#{s})",s.map{|i|i}[1]