Sort an array of hashes by given key
sorted = array.sort {|a, b| a[key] <=> b[key]}
Note that this is different from:
sorted_symbol = array.sort{ |a, b| a[:key] <=> b[:key]}
Written by Melanie Archer
Related protips
1 Response

sorted = array.sort_by { |x| x[key] }
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Ruby
Authors
Related Tags
#ruby
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#