I have an array of arrays like so:
irb(main):028:0> device_array
=> [["name1", "type1", ["A", "N", "N"], ["Attribute", "device_attribute"], 9], ["name2","type2", ["A", "N", "N"], ["Attribute", "device_attribute"], 7]]
I would like to sort the entire device_array on the 4th element.
I've tried
AllDevicesController.all_devices.sort do | a,b |
for i in 0..(AllDevicesController.all_devices.length - 1) do
a[i][4] <=> b[i][4]
end
end
I've also tried:
AllDevicesController.all_devices.sort do | a,b |
a[][4] <=> b[][4]
end
Both methods have not worked.
I was using this as a reference: http://ariejan.net/2007/01/28/ruby-sort-an-array-of-objects-by-an-attribute/
I imagine I'm missing something rubyish that makes this really easy.