Write a method which takes in a string and returns an array of pairs

How do I write a method which takes in a string and returns an array of
pairs each pair contains the next distinct letter in the string, and the
number consecutive repeats?

Thank you

Sounds like fun, I’ll have a go since I’ve never done something like
that before…

Here’s one way to do it. If this is homework then you’d better be able
to explain to your teacher how it works; so I recommend doing some
studying of the objects and methods involved: “String#scan”, “Regexp”,
“Capturing Groups”, “Enumerable#map”, “Array”, and “String#length”

‘moossse’.scan(/(\w)(\1*)/).map{|a,b|[a,b.length+1]}