Created
September 14, 2009 21:38
-
-
Save javan/186950 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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