From: Derek Cannon Date: 2010-04-24T01:53:43+09:00 Subject: Re: Best way to write this method? You are right about my initial coding being incorrect. I noticed it hours after first posting, and changed it to: def elements_overlap?(a, b) array = a.to_a & b.to_a !array.empty? end def overlaps?(a, b) if not elements_overlap?(a.keys, b.keys) return false else a.each_key { |i| # :m, :w if elements_overlap?(a[i], b[i]) return true end } end return false end And I tested it, and it seemed to work in all the following instances: a = {:monday => [get_time("9:00am-10:00am")], :wednesday => [get_time("11:00am-12:00pm")] } b = {:monday => [get_time("11:00am-12:00pm")], :wednesday => [get_time("9:00am-10:00am")] } c = {:tuesday => [get_time("9:00am-10:00am")], :thursday => [get_time("11:00am-12:00pm")] } d = {:monday => [get_time("11:00am-12:00pm")], :wednesday => [get_time("2:00pm-5:00pm"), :friday => [get_time("9:00am-10:00am")], ] } e = {:monday => [get_time("6:00am-8:00am"), get_time("9:00am-10:00am")], :wednesday => [get_time("6:00am-8:00am")] } # M1W2 and M2W1 share times => expected false puts overlaps?(a, b) # => false # Same times and days => expected true puts overlaps?(a, a) # => true # Same times; different days => expected false puts overlaps?(a, c) # => false # Different times, same time F2 as M1W1 => expected false puts overlaps?(a, d) # => false # Second time on M2 overlaps M1 time => expected true puts overlaps?(a, e) # => true 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! -- Derek Cannon -- Posted via http://www.ruby-forum.com/.