title: How to make dynamic multi-dimensional array in ruby?
body: <p>I have a beginner ruby question about multi dimensional arrays.</p>
  
  <p>I want to sort entries by year and month. So I want to create a multi-dimensional array that would contain years -> months -> entries of month</p>
  
  <p>So the array would be like:</p>
  
  <pre><code>2009 -&gt;
         08
            -&gt; Entry 1
            -&gt; Entry 2
         09
            -&gt; Entry 3
  2007 -&gt;
         10
            -&gt; Entry 5
  </code></pre>
  
  <p>Now I have:</p>
  
  <pre><code>@years = []
  @entries.each do |entry|
      timeobj = Time.parse(entry.created_at.to_s)
      year = timeobj.strftime("%Y").to_i
      month = timeobj.strftime("%m").to_i
      tmparr = []
      tmparr &lt;&lt; {month=&gt;entry}
      @years.push(year)
      @years &lt;&lt; tmparr
  end
  </code></pre>
  
  <p>but when I try to iterate through the years array, I get: "undefined method `each' for 2009:Fixnum"</p>
  
  <p>Tried also:</p>
  
  <pre><code>@years = []
  @entries.each do |entry|
      timeobj = Time.parse(entry.created_at.to_s)
      year = timeobj.strftime("%Y").to_i
      month = timeobj.strftime("%m").to_i
      @years[year][month] &lt;&lt; entry
  end
  </code></pre>