Just use gsub
and regexp.
For example:
str = "foo bar bar baaar"
str.gsub(/\s+/, " ")
will return new string or you can modify str directly using gsub!
.
BTW. Regexp are very useful - there are plenty resources in the internet, for testing your own regexpes try rubular.com for example.