# Calendar hash

**URL:** <https://www.ruby-forum.com/t/calendar-hash/192896>\
**Category:** Rails\
**Created:** [August 7, 2010, 10:27pm UTC](https://www.ruby-forum.com/t/calendar-hash/192896 "2010-08-07T22:27:15Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![landge](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/b5e925/32.png) [@landge](https://www.ruby-forum.com/u/landge)\
**Post date:** [August 7, 2010, 10:27pm UTC](https://www.ruby-forum.com/t/calendar-hash/192896/1 "2010-08-07T22:27:15Z")

</div>

Hi!

I’m trying to create a nested hash which should hold the dates  
in my database as a kind of calendar. What I did so far is obviously  
wrong,  
because I’m storing the week-number for every day in the week array.  
I don’t really understand nested hashes and can’t find the solution.

what am I doing wrong here?? What’s the right way of doing this??

11 @calendar = Hash.new{|h,k| h[k]=Hash.new(&h.default\_proc) }  
12 week = []  
13 Dates.find(:all).each do |row|  
14 date = Date.strptime(str="#{row.dato}")  
15 year = date.cwyear  
16 month = date.mon  
17 week \<\< date.cweek  
18 @calendar[year][month] = week  
19 end

thanks in advance,

floke
