From: ahoward Date: 2003-03-22T05:04:59+09:00 Subject: Re: infinite Time (solved) On Sat, 22 Mar 2003 nobu.nokada@softhome.net wrote: > You need to coerce. thanks! didn't know Time.coerce existed... > Float#> doesn't call <=> due to performance. but class << INF include Comparable ... end should create a '>' correct? anyhow, this seems to work fine : ----CUT---- class Time INF = INFINITY = 1.0 / 0 NINF = NEGATIVE_INFINITY = -1.0 / 0 EPOCH = Time.at(0) class << INFINITY include Comparable def <=> o;id == o.id ? 0 : 1;end end class << NEGATIVE_INFINITY include Comparable def <=> o;self.id == o.id ? 0 : -1;end end def coerce(x) case x when Float return [x, to_f] when Integer return [x, to_i] else super end end end # a test def display command puts "\t#{command}" puts "\t\t# >> #{eval command}" end $now = Time.now objects = %w(Time::INF Time::NINF $now) objects.map do |a| puts '========' objects.map do |b| puts "\t--------" %w(<=> <= >= < > ==).map do |op| display "#{a} #{op} #{b}" end end end ----CUT---- -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 ====================================