How I can sort array data alphanumerically in ruby?
Suppose my array is a = [test_0_1, test_0_2, test_0_3, test_0_4, test_0_5, test_0_6, test_0_7, test_0_8, te
a = [test_0_1, test_0_2, test_0_3, test_0_4, test_0_5, test_0_6, test_0_7, test_0_8, te
If you simply sort as string, you will not get the correct ordering between 'test_2' and 'test_10', for example. So do:
sort_by{|s| s.scan(/\d+/).map{|s| s.to_i}}.reverse