Skip to content

Instantly share code, notes, and snippets.

@aarti
Created January 23, 2014 16:34
Show Gist options
  • Select an option

  • Save aarti/8581844 to your computer and use it in GitHub Desktop.

Select an option

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
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