I have an array:
arr = ["Bar", "abc", "foo", "1", "20”, "10", "_def"]
I need to sort using case-insensitive alphabetically first, then numerically followed by special characters.
I am trying to use sort_by:
irb(main):071:0> arr.sort_by {|s| [s[/[0-9a-z]+/], s.to_i]}
=> ["1", "10", "20", "abc", "Bar", "_def", "foo"]
The output has to be:
arr = ["abc", "Bar", "foo", "1", “10”, “20", "_def"]