title: How to sort map by field in ruby
body: <p>I'm trying to sort the below object list by distance field. I'm having no success</p>
  <p>here is the structure:</p>
  <p><code>[{&quot;id&quot;=&gt;13, &quot;distance&quot;=&gt;&quot;6612.9&quot;},{&quot;id&quot;=&gt;2, &quot;distance&quot;=&gt;&quot;512.9&quot;},{&quot;id&quot;=&gt;, &quot;distance&quot;=&gt;&quot;343.9&quot;}]</code></p>
  <p>here is the map</p>
  <p><code>itemmap = items.map { |item| item.attributes.merge(distance: get_item_distance(item,[params[:latitude], params[:longitude]]).try(:round, 1) }</code></p>
  <p>Then for sorting I tried the below method but non worked</p>
  <p><code>itemmap.sort_by(&amp;:distance)</code></p>
  <p><code>itemmap.sort_by { |k, v| v[:distance] }</code></p>
  <p><code>itemmap.map {|item| item.distance }</code></p>
  <p><code>itemmap.sort_by {|item| item.distance}</code></p>