Ruby Squeeze
Ruby has a method to remove repeating characters in a string called squeeze
"foobar".squeeze
# => "fobar"
"foo foo bar".squeeze
# => "fo fo bar"
It also accepts args to narrow down the specific characters for which you would want to remove repeats:
"foobar hello world".squeeze("o")
# => "fobar hello world"
"foobar hello world".squeeze(" ")
# => "foobar hello world"
Tweet