From: Robert Klemme Date: 2004-07-30T17:51:43+09:00 Subject: Re: Time checking, efficient? "Phano" schrieb im Newsbeitrag news:lKnOc.99670$dP1.342027@newsc.telia.net... > --- copy --- > module Strict > class StrictError < Exception > end > > class TimeCheck < Time > def TimeCheck.gm( *args ) > month = args[1] || 1 > time = Time.gm( *args ) > raise StrictError.new('Days out of range') if time.month != month > time > end > end > end > --- end --- > > I want to check if a Time is in the right boundraries more strictly than the > Time class already does. > Time.gm( 2004,2,30 ) -> Mon Mar 01 00:00:00 UTC 2004 > Time*Check.gm( 2004,2,30 ) -> StrictError > > Would the above module be efficient or could this be done in another way? Some remarks: you don't need to inherit Time. I'd do probably def Time.gm_checked( year, month=1, day=1, hour=0, min=0, sec=0, usec=0) gmt = Time.gm( year, month, day, hour, min, sec, usec ) raise ArgumentError, 'Value out of range' unless gmt.year == year && gmt.month == month && gmt.day == day && gmt.hour == hour && gmt.min == min && gmt.sec == sec && gmt.usec == usec gmt end But probably month is sufficient since Time.gm will take care of other violations. robert