Skip to content

Instantly share code, notes, and snippets.

@javan
Created September 14, 2009 18:58
Show Gist options
  • Save javan/186847 to your computer and use it in GitHub Desktop.
Save javan/186847 to your computer and use it in GitHub Desktop.
# Takes a collection of Stocks and moves the closed ones to the end
def closed_stocks_last(stocks)
open, closed = [], []
stocks.each do |stock|
if stock.closed?
closed << stock
else
open << stock
end
end
open + closed
end
# I've found that doing:
stocks.sort_by { |s| s.closed? ? 1 : 0 }
# Does not preserve the original ordering, but using the method above does.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment