I have a variable containing a string like this in Ruby 1.9.3
#HELLO
#HELLO
#HELLO
#HELLO
#WORLD
#WORLD
#WORLD
#WORLD
#FOO
#BAR
#WORLD
I'd like it to be transformed to something like :
4 times #HELLO end
4 times #WORLD end
#FOO
#BAR
#WORLD
That's to say, I'd like consecutive duplicate strings to be grouped into one with the amount aside.
Is there a clever way of doing this using Ruby's functional programming power or other techniques ?