Sort an array according to the elements of another array May 30, 2023 by Tarik I’ll be surprised if anything is much faster than the obvious way: a2.sort_by{|x| a1.index x.id}