From: Robert Klemme Date: 2010-04-24T17:10:23+09:00 Subject: Re: Best way to write this method? On 23.04.2010 18:53, Derek Cannon wrote: > I do appreciate your response Robert. If you wouldn't mind educating me > a little further on your approach to this problem... I don't understand > how adding multiple classes to this code would be implemented. If you > wouldn't mind giving me a brief summary of what you'd think would belong > in these classes you purposed, I'd be very grateful! Oh, I had thought that I did that already. OK, here's a short list: TimeTable - maintains a collection of TimeRange per weekday - responsible for adding and removing TimeRanges - can check for overlap with another TimeTable TimeRange - a time range within a single day - invariant 0 <= start < end <= 23 - can check for overlap with another TimeRange Overlap checks follow rules you gave. Btw, I just notice that my implementation was stupid because it does to much work. This is better a.any? do |day, r1| r2 = b[day] and range_overlaps?(r1, r2) end Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/