def calendar(month,year)
  days = month_days(month,year)
  t = Time.mktime(year,month,1)
  first = t.wday
  list = *1..days
  weeks = [[]]
  week1 = 7 - first
  week1.times { weeks[0] << list.shift }
  nweeks = list.size/7 + 1
  nweeks.times do |i|
    weeks[i+1] ||= []
    7.times do
      break if list.empty?
      weeks[i+1] << list.shift
    end
  end
  pad_first = 7-weeks[0].size
  pad_first.times { weeks[0].unshift(nil) }
  pad_last = 7-weeks[0].size
  pad_last.times { weeks[-1].unshift(nil) }
  weeks
end
arr = calendar(12,2008)    # [[nil, 1, 2, 3, 4, 5, 6],
                           # [7, 8, 9, 10, 11, 12, 13],
                           # [14, 15, 16, 17, 18, 19, 20],
                           # [21, 22, 23, 24, 25, 26, 27],
                           # [28, 29, 30, 31, nil, nil, nil]]

