title: How to rewrite this each loop in ruby?
body: <p>I have this loop:</p>
  
  <pre><code>  stations = Station.where(...)
    stations.all.each do |s|
      if s.city_id == city.id
        show_stations &lt;&lt; s
      end
    end
  </code></pre>
  
  <p>This works well, but because of looping the all the data, I think it's kinda slow. I've tried to rewrite it with using <code>select</code>, like this:</p>
  
  <pre><code>show_stations &lt;&lt; stations.select { |station| station.city_id == city.id}
  </code></pre>
  
  <p>But the amount of saved data into <code>show_stations</code> is different compared to the <code>each</code> version and then, the data are in different format (array/object).</p>
  
  <p>Is there any better/faster way to rewrite the loop version?</p>