Created
January 23, 2014 16:34
-
-
Save aarti/8581844 to your computer and use it in GitHub Desktop.
Sort or Sort_by could do the same thing since they both take a block
This file contains hidden or 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
| a =[{n: 1}, {n: 5}, {n: 3}] | |
| a.sort {|x,y| x[:n]<=>y[:n] } #=> [{:n=>1}, {:n=>3}, {:n=>5}] | |
| a.sort_by{|x| x[:n].to_i } #=> [{:n=>1}, {:n=>3}, {:n=>5}] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment