I have an array that is currently sorted alphabetically, and I'm trying to sort it by a manual order of strings.
Current code:
list = ["gold","silver","bronze","steel","copper"]
list = list.sort { |a, b| a <=> b }
What I'm trying to achieve: (With a blank entry as a separator)
list = ["gold","silver","bronze","steel","copper"]
sort_order = ["bronze","silver","gold","","copper","steel"]
list = list.sort_by sort_order
Output: bronze | silver | gold | - | copper | steel
Is this possible? Currently stuck with these error messages:
comparison of Integer with nil failed
comparison of String with String failed