From: Carlos Date: 2004-08-27T21:56:23+09:00 Subject: Re: Code Critique Request [James Edward Gray II , 2004-08-26 22.37 CEST] ... > This week's Regular Quiz (there also an Expert Quiz) came out last > night. The curious can read it here: > > http://article.gmane.org/gmane.comp.lang.perl.qotw.quiz-of-the-week/105 ... > If any of you can spare the time, I would appreciate an honest review > of the code I generated. I'm interested in any opinions you might have > about constructs, style, whatever. I'm especially looking for things > I'm handling in a non-Ruby fashion. Break my bad habits before they > take hold... Hi, James: I didn't try your code, but I've seen that you don't use the builtin Date class, neither you have an array with the month's length. So I guess your program will think that an event scheduled for the 31st of the month will happen tomorrow, if today is the 30th April. (Sorry if I'm mistaken.) By the way, I would solve this in the non-object-oriented (and maybe non-rubyesque) way of putting the events in nested hashes, as in the following sketch: events = { # first level: days 1 => { # second level: months "*" => [ "Pay day" ], 1 => { # third level: years "*" => [ "New year", "First day" ], 2005 => [ "First day of 2005" ] }, 2 => ... }, 2 => ... } And later, retrieve the events by looping so: d = Date.today # n is the parameter n.times do e = [ events[d.day]["*"] ] if x = events[d.day][d.mon] e += [ x["*"], x[d.year] ] end e.flatten! ...etc... d += 1 end HTH