I have an array of arrays like so:
irb(main):028:0> device_array => [[\"name1\", \"type1\", [\"A\", \"N\", \"N\"], [\"Attribute\", \"device_attribute\"], 9
sort_by
Instead of using spaceship operator (<=>) give a try to sort_by
<=>
device_array.sort_by { |el| el[4] }
Though if you know that the forth element is the last one, you can use el.last too in the block.
el.last
Ruby docs: Enumerable#sort_by