Solution to 99 lisp problems, p09 in ruby
Here is solution that aims to solve the described problem.

Note that your initial solutions is doing more that the problem requires, you are handling string instead of lists, are ordering them, and the output isn't the one desired by the problem.

require 'minitest/autorun'

class L99
  # P09 (**) Pack consecutive duplicates of list elements into sublists.
  # If a list contains repeated elements they should be placed in separate sublists.
  def self.pack(list)
    list.slice_when { |i, j| i != j }.to_a
  end
end

class PackTest &lt; Minitest::Test
  def test_pack
    list = %i[a a a a b c c a a d e e e e]
    expected = [%i[a a a a], [:b], %i[c c], %i[a a], [:d], %i[e e e e]]

    assert_equal expected, L99.pack(list)
  end

  def test_pack_string
    str = 'putanytexthere'
    expected = [['a'], %w[e e e], ['h'], ['n'], ['p'], ['r'], %w[t t t], ['u'], ['x'], ['y']]


    assert_equal expected, L99.pack(str.each_char.sort)
  end
end