title: Ruby: Grouping a date range by year and month
body: <p>I am creating a range for each month in my example range.  </p>
  
  <pre><code>example_range = (Time.zone.today..2.years.from_now)
  </code></pre>
  
  <p>Output should look like so:</p>
  
  <pre><code>=&gt; [Wed, 03 Aug 2016..Wed, 31 Aug 2016, Thu, 01 Sep 2016..Fri,
  30 Sep 2016, Sat, 01 Oct 2016..Mon, 03 Oct 2016, ...]  
  </code></pre>
  
  <p>At the moment I'm doing this, which doesn't work for ranges longer than a year, because the grouping will put January '16 and January '17 in one group.</p>
  
  <pre><code>example_range.group_by(&amp;:month).each { |_, month| month.first..month.last } 
  </code></pre>
  
  <p>I also tried this, but ruby segfaults on this for some reason...</p>
  
  <pre><code>example_range.group_by(&amp;:year).map{ |ary| ary.group_by(&amp;:month)}
  </code></pre>
  
  <p>Does anyone know a more beautiful (or at least working) way of doing this?</p>