From this question (@mudasobwa);
input.sort_by { |h| sorter.index(h[:id]) }
In some unfortunate cases; sorter.index(h[:id]) returns nil, it then returns an error
How would one cleanly avoid such error to happen, while having the rest of the array sorted ?
|| -1if you want them at the start or|| sorter.sizeif you want them at the end.|| -Float::INFINITY.-Float::INFINITYwill do the same as-1. You can put it as an alternative to the index. Akasorter.index(h[:id]) || -Float::INFINITY.