Skip to content

Instantly share code, notes, and snippets.

@vdw
Last active August 29, 2015 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vdw/2fabb09c397e25d46930 to your computer and use it in GitHub Desktop.
Save vdw/2fabb09c397e25d46930 to your computer and use it in GitHub Desktop.
Sort array of objects based on given order of ids (ruby)
my_hash = {}

@objects.each { |obj| my_hash[obj.id] = obj }

my_array.collect{ |id| my_hash[id] }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment