From: David Alan Black Date: 2001-02-24T00:32:37+09:00 Subject: [ruby-talk:11383] Re: Time without seconds (updated/fixed) On Sat, 24 Feb 2001, Kevin Smith wrote: > ts wrote: > > Warning you can have a problem > > See that t is a Time object and not a MyTime object. > > Thanks. You are correct. Fortunately, that is > easily fixed: > > class MyTime < Time > def MyTime.createFloor > t = Time.new > return MyTime.at(t.to_i() - > t.sec) > end > def toto > puts "toto" > end > end > t = MyTime.createFloor > p t.inspect > p t.type > t.toto Here's a followup question, based on playing around with this: Why do the two ways of doing this (which I've stashed into MyTime.floor) result in objects of different types? class MyTime < Time def MyTime.floor # Way 1 t = Time.new mt = MyTime.at t - t.sec # Way 2 tt = MyTime.at (tm = Time.new) - tm.sec [mt,tt].each do |ti| puts "#{ti} is of type #{ti.type}" end end end MyTime.floor Output: Fri Feb 23 10:31:00 EST 2001 is of type MyTime Fri Feb 23 10:31:00 EST 2001 is of type Time David -- David Alan Black home: dblack@candle.superlink.net work: blackdav@shu.edu Web: http://pirate.shu.edu/~blackdav