Q:

Ruby array group_by with dynamic elements

array = ["a > 1 2 3", "a > 4 5 6", "a > 7 8 9", "b > 1 2 3", "b > 4 5 6", "b > 7 8 9", "b > 10 11 12"]

I'm trying to group/split an array by the beginning value of the string.  I know I can use group_by if the elements are static...    
array.group_by{|t| t[0]}.values

array = [["a > 1 2 3", "a > 4 5 6", "a > 7 8 9"], ["b > 1 2 3", "b > 4 5 6", "b > 7 8 9", "b > 10 11 12"]]

but anything before " > " is dynamic so I don't know how to 'match' 'a', 'b' to be bale to group them. 

A:

You could do with:
array.group_by { |t| t.split(/\s*>\s*/).first }.values

