Skip to content
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

Merged
merged 1 commit into from May 19, 2016

Conversation

jeremy
Copy link
Member

@jeremy jeremy commented May 17, 2016

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.

@jeremy jeremy force-pushed the ruby24-integer-unification branch 3 times, most recently from 4eb277a to 01d1a9f Compare May 17, 2016 17:25
@kaspth
Copy link
Contributor

kaspth commented May 17, 2016

LGTM :shipit:

[Fixnum, Bignum, Float, BigDecimal].each do |klass|
klass.prepend(ActiveSupport::NumericWithFormat)
# Ruby 2.4+ unifies Fixnum & Bignum into Integer.
if Integer == Fixnum
Copy link
Contributor

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 Fixnumis directly referenced? Should we check for the ruby version explicitly instead?

Copy link
Member Author

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.

Copy link
Contributor

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

Copy link
Member Author

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.

Copy link
Contributor

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 == Fixnum

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.


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.
@jeremy jeremy force-pushed the ruby24-integer-unification branch from 01d1a9f to 89e2f7e Compare May 19, 2016 04:59
@jeremy jeremy merged commit 89e2f7e into rails:master May 19, 2016
@jeremy jeremy deleted the ruby24-integer-unification branch May 19, 2016 05:03
@jeremy jeremy added this to the 5.0.1 milestone May 19, 2016
@jeremy
Copy link
Member Author

jeremy commented May 19, 2016

5-0-stable: dd7d5b7

@vipulnsward
Copy link
Member

@jeremy needs a CHANGELOG?

@jeremy
Copy link
Member Author

jeremy commented May 19, 2016

@vipulnsward I wrote one but removed it. From users' point of view, nothing changes.

@vipulnsward
Copy link
Member

Probably the class name? Not sure if people might rely on it though, so 👍

@rafaelfranca
Copy link
Member

👍

aliuk2012 added a commit to ministryofjustice/correspondence_tool_staff that referenced this pull request Oct 9, 2018
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
aliuk2012 added a commit to ministryofjustice/correspondence_tool_staff that referenced this pull request Oct 10, 2018
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants