Skip to content

Instantly share code, notes, and snippets.

@javan
Created September 14, 2009 21:38
Show Gist options
  • Save javan/186950 to your computer and use it in GitHub Desktop.
Save javan/186950 to your computer and use it in GitHub Desktop.
# Sorry for the confusing stock names. Their name does not indicate the order they should be in. "second" is the only closed stock.
# The original ordering
>> stocks.map(&:name)
=> ["second", "third", "first"]
# Ordering from #sort_by
>> stocks.sort_by { |s| s.closed? ? 1 : 0 }.map(&:name)
=> ["first", "third", "second"]
# Ordering using method from: http://gist.github.com/186847
# This is the correct order I'm seeking.
>> closed_stocks_last(stocks).map(&:name)
=> ["third", "first", "second"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment