Skip to content

Instantly share code, notes, and snippets.

@Altech
Created June 16, 2013 07:36
Show Gist options
  • Save Altech/5791289 to your computer and use it in GitHub Desktop.
Save Altech/5791289 to your computer and use it in GitHub Desktop.
squeeze in Ruby.
class String
def squeeze(c)
s = ""
now = false
0.upto(self.size-1) do |i|
if self[i] == c
if now
next
else
s << self[i]
now = true
end
else
s << self[i]
now = false
end
end
return s
end
def squeeze2(c)
self.gsub(/#{c}+/,c)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment