From: ahoward Date: 2003-03-22T03:44:31+09:00 Subject: Re: infinite Time On Sat, 22 Mar 2003 nobu.nokada@softhome.net wrote: > class Time > NEGATIVE_INFINITY = -1.0 / 0 > INFINITY = 1.0 / 0 > EPOCH = 0 > end looks promising. however, can anyone explain why this approach to implementing the comparisions does not work????? class Time INF = INFINITY = 1.0 / 0 NINF = NEGATIVE_INFINITY = -1.0 / 0 EPOCH = Time.at(0) class << INFINITY include Comparable def <=> o;self.id == o.id ? 0 : 1;end end class << NEGATIVE_INFINITY include Comparable def <=> o;self.id == o.id ? 0 : -1;end end end def display command puts "#{command}" puts "\t# >> #{eval command}" end display %Q(Time::INF <=> Time::NINF) display %Q(Time::NINF <=> Time::INF) display %Q(Time.now <=> Time::INF) display %Q(Time::INF <=> Time.now) display %Q(Time.now <=> Time::NINF) display %Q(Time::NINF <=> Time.now) # why does this raise an exception?? display %Q(Time::INF > Time.now) i could use singleton objects for INF and NINF, but would like to avoid that. i am unclear as to why class << object include Comparable def <=> ... end does NOT, in this case, seem to redefine the '>' operator. i swear, every time i think i understand this bloody 'class << self' business... i *thought* the above would (re)define all the comparison operators for the singleton class of INF... -a -- ==================================== | Ara Howard | NOAA Forecast Systems Laboratory | Information and Technology Services | Data Systems Group | R/FST 325 Broadway | Boulder, CO 80305-3328 | Email: ahoward@fsl.noaa.gov | Phone: 303-497-7238 | Fax: 303-497-7259 ====================================