I have an array of objects sorted by created_at (which is of course a Time object)
I have a hash of objects which looks lik开发者_Go百科e
{
time_in_integer1 => object1,
time_in_integer2 => object2,
time_in_integer3 => object3,
....
}
I would like to insert object1, 2, 3 into the array in the most efficient manner, sorted by comparing the created_at with the keys in the hash.
What would be the best way to achieve this?
See http://www.ruby-forum.com/topic/134477#599091.
This should do it:
my_array = (my_array + my_hash.values).sort_by {|obj| obj.created_at }
精彩评论