Problems with dates?

Hello. I'm fairly new to ruby, but hit a snag already. I'm writing a
small .rhtml file that will display a dynamic calendar. Its pretty
basic right now, consisting of a simple html table and some css. I
also wrote a Calendar class, included below, to assist with the task.
The problem is that apache mod_ruby segfaults! I've tried running via
the command-line with both erb and eruby. erb corrupts the output,
putting the dynamically generated stuff at the top, above the static
html code. eruby seems to handle it fine most of the time, but I have
seen errors from it as well, reporting an error at
/usr/lib/ruby/1.8/date.rb line 305. I'm running apache 2.0.54, ruby
1.8.3, mod_ruby 1.2.4 on Gentoo Linux.

Thanks in advance,
Russ

<% require 'date'; require 'calendar' %><?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/
DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>Date Test</title>
<link rel="stylesheet" type="text/css" href="home.css"/>
</head>
<body>
<div class="content">
<div>
<% d = Date.today %>
<table class="calendar"><caption><a href="#"><%= Date::MONTHNAMES[d.month] + ' '
+ d.year.to_s %></a></caption><thead><tr>
<% Date::TINY_DAYNAMES.each do |name| %>
  <th><%= name %></th> <% end %>
  </tr></thead><tbody><tr>
<% cal = Calendar.new(Date.today.year)
  mo = cal.getMonth(Date.today.month)
  for weeks in 0...mo.length
    wk = mo[weeks]
    print '<tr>'
    for dy in 0...wk.length
      style = Array.new
      title = nil
      if (wk[dy] == Date.today)
        style.push 'today'
        title = 'today'
      end
      style.push 'other' if (wk[dy].month != Date.today.month)
      print '<td'
      print ' class="' + style.to_s + '"' if (style.length > 0)
      print ' title="' + title + '"' if (title)
      print '>' + wk[dy].day.to_s + '</td>'
    end
    puts '</tr>'
  end %>
  </tbody></table>
</div>
</div></body></html>

/usr/lib/ruby/site-ruby/calendar.rb:
require 'date'

class Date
   TINY_DAYNAMES = %w(S M T W T F S)
end

class Calendar
   def initialize(year=Date.today.year)
      @year = year
   end

   def add(event)
      list = allEvents[event.date]
      list = Array.new if (!list)
      list.push(event)
      allEvents[event.date] = list
      monEvents = @monthly[event.date.month]
   end

   def getMonth(mo)
      dt = Date.new(@year, mo, 1)
      i = dt.month
      list = Array.new
      while i != (mo+1) % 12
         wk = getWeek(dt.month, dt.day)
         dt = wk[6].succ
         i = dt.month
         list.push(wk)
      end
      list
   end

   def getWeek(mo, dy)
      dt = Date.new(@year, mo, dy)
      dt -= dt.wday
      list = Array.new
      for i in 0..6
         list.push dt
         dt = dt.succ
      end
      list
   end

   def getDay(mo, dy)
      Date.new(@year, mo, dy)
   end
end