New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for unified Integer class in Ruby 2.4+ #25056
Conversation
4eb277a
to
01d1a9f
Compare
LGTM |
[Fixnum, Bignum, Float, BigDecimal].each do |klass| | ||
klass.prepend(ActiveSupport::NumericWithFormat) | ||
# Ruby 2.4+ unifies Fixnum & Bignum into Integer. | ||
if Integer == Fixnum |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Didn't the feature mention warning when Fixnum
is directly referenced? Should we check for the ruby version explicitly instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's undecided; there's no warning currently. It may be too noisy to tolerate for widespread use. Prefer feature detection to implementation version checks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair enough. If nothing else we could move the Integer.prepend
case outside of the conditional. Perhaps something like this:
Integer.prepend(ActiveSupport::NumericWithFormat)
if defined?(Bignum) && Bignum.ancestors.exclude?(ActiveSupport::NumericWithFormat)
Bignum.prepend(ActiveSupport::NumericWithFormat)
end
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the suggestions. That prepends Fixnum's ancestor, not Fixnum, so no go.
To avoid referencing Fixnum entirely, the simple route is checking 1.class == Integer
. I didn't litter the code with this (there are half a dozen other cases) because it's speculating how—and whether—Fixnum references will spam warnings. Poor trade for unknown benefit. There's little drawback to waiting to see what drops on Ruby trunk.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
On Wed, May 18, 2016, 6:30 PM Jeremy Daer notifications@github.com wrote:
In activesupport/lib/active_support/core_ext/numeric/conversions.rb
#25056 (comment):@@ -134,6 +134,12 @@ def to_formatted_s(*args)
deprecate to_formatted_s: :to_s
end-[Fixnum, Bignum, Float, BigDecimal].each do |klass|
- klass.prepend(ActiveSupport::NumericWithFormat)
+# Ruby 2.4+ unifies Fixnum & Bignum into Integer.
+if Integer == FixnumThanks for the suggestions. That prepends Fixnum's ancestor, not Fixnum,
so no go.To avoid referencing Fixnum entirely, the simple route is checking 1.class
== Integer. I didn't litter the code with this (there are half a dozen
other cases) because it's speculating how—and whether—Fixnum references
will spam warnings. Poor trade for unknown benefit. There's little drawback
to waiting to see what drops on Ruby trunk.—
You are receiving this because you commented.
Reply to this email directly or view it on GitHub
https://github.com/rails/rails/pull/25056/files/01d1a9f97fdda379ed47a737d2416b2139209cb7#r63794236
Ruby 2.4 unifies Fixnum and Bignum into Integer: https://bugs.ruby-lang.org/issues/12005 * Forward compat with new unified Integer class in Ruby 2.4+. * Backward compat with separate Fixnum/Bignum in Ruby 2.2 & 2.3. * Drops needless Fixnum distinction in docs, preferring Integer.
01d1a9f
to
89e2f7e
Compare
5-0-stable: dd7d5b7 |
@jeremy needs a CHANGELOG? |
@vipulnsward I wrote one but removed it. From users' point of view, nothing changes. |
Probably the class name? Not sure if people might rely on it though, so 👍 |
👍 |
As of Ruby 2.4, Fixnum and Bignum have been removed and we should now be using Integer. https://bugs.ruby-lang.org/issues/12005 rails/rails#25056
As of Ruby 2.4, Fixnum and Bignum have been removed and we should now be using Integer. https://bugs.ruby-lang.org/issues/12005 rails/rails#25056
Ruby 2.4 unifies Fixnum and Bignum into Integer: https://bugs.ruby-lang.org/issues/12005