Hi --
split() rules the world. squeez()...not so much.
s.split().join(" ")
They're completely different methods, though. They're not in a death
struggle
They do different things. I wouldn't want to try this
with split:
"abc deffff ghi".squeeze(" f") => "abc def ghi"
squeeze is a better fit, it terms of its stated purpose, than split,
if you want to condense multiple occurrences into one. It's also
faster, in every benchmark I can come up with:
user system total real
2.630000 0.010000 2.640000 ( 2.665775)
0.140000 0.000000 0.140000 ( 0.136925)
(That's for removing extra " "s from a string of length about 500.)
David
--
David A. Black / Ruby Power and Light, LLC
Ruby/Rails consulting & training:
http://www.rubypal.com
Now available: The Well-Grounded Rubyist (
http://manning.com/black2)
Training! Intro to Ruby, with Black & Kastner, September 14-17
(More info:
http://rubyurl.com/vmzN)