Here are three other ways, for:
aoa = [1, 'cat', [3, 4], 5, [6, 7, 8], 9]
1
is_array = ->(e) { Array===e }
[aoa.reject(&is_array)].concat(aoa.select(&is_array))
#=> [[1, "cat", 5, 9], [3, 4], [6, 7, 8]]
2
Adding a step to @Doguita's use of Enumerable#partition:
a, e = aoa.partition { |e| Array===e }
[e,*a]
#=> [[1, "cat", 5, 9], [3, 4], [6, 7, 8]]
3
sorted = aoa.sort_by { |e| (Array===e) ? 1 : 0 }
[sorted.shift(aoa.count { |e| !(Array===e) })].concat(sorted)
#=> [[1, "cat", 9, 5], [6, 7, 8], [3, 4]]
What if aoa contains only arrays?
All of these methods will return an array containing an empty array if all the elements of aoa are arrays. If an empty array is not desired, tack .reject(&:empty?) to the end. For example:
aoa = [[3, 4], [6, 7, 8]]
[aoa.reject(&is_array)].concat(aoa.select(&is_array))
#=> [[], [3, 4], [6, 7, 8]]
[aoa.reject(&is_array)].concat(aoa.select(&is_array)).reject(&:empty?)
#=> [[3, 4], [6, 7, 8]]
aoa = [1, 'cat', 5, 9]
[aoa.reject(&is_array)].concat(aoa.select(&is_array))
#=> [[1, "cat", 5, 9]]
[aoa.reject(&is_array)].concat(aoa.select(&is_array)).reject(&:empty?)
#=> [[1, "cat", 5, 9]]
You can instead use reject!, but if you do, avoid the pitfall!
You can replace reject(&:empty?) with reject!(&:empty?), which is a bit more efficient, but if you do, remember than reject! returns nil if no change is made, so you need to write:
aoa = [1, 'cat', 5, 9]
arr = [aoa.reject(&is_array)].concat(aoa.select(&is_array))
#=> [[1, "cat", 5, 9]]
arr.reject!(&:empty?)
#=> nil
arr
#=> [[1, "cat", 5, 9]]