Project

General

Profile

Actions

Feature #17825

open

Uniformize Float::INFINITY and Date::infinity.new

Added by Aoernis (lucas billaudot) over 3 years ago. Updated over 3 years ago.

Status:
Open
Assignee:
-
Target version:
-
[ruby-core:103587]

Description

With Float you can do

Float::INFINITY # Infinity

and with Date you can do

Date::Infinity.new # #<Date::Infinity:0x00007f8d46a59ee0 @d=1>

but not

Date::INFINITY # uninitialized constant Date::INFINITY

Background

Date::Infinity.new and Float::INFINITY have both the same ancestors and have same using purpose
So it feel odd no be able to call them the same way

Proposal

Just make Date::INFINITY a working thing
And maybe mark Date::Infinity.new as deprecated ¯_(ツ)_/¯

Thanks for reading

Updated by nobu (Nobuyoshi Nakada) over 3 years ago

  • Description updated (diff)

It's hard to remove that class because of marshal compatibility.

diff --git a/ext/date/lib/date.rb b/ext/date/lib/date.rb
index 65c34ace492..e96d102d7da 100644
--- a/ext/date/lib/date.rb
+++ b/ext/date/lib/date.rb
@@ -9,6 +9,8 @@
     false
   end
 
+  INFINITY = Float::INFINITY # :nodoc:
+
   class Infinity < Numeric # :nodoc:
 
     def initialize(d=1) @d = d <=> 0 end
@@ -60,4 +62,5 @@
 
   end
 
+  deprecate_constant :Infinity
 end
Actions

Also available in: Atom PDF

Like0
Like0