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

Projects
None yet
6 participants
@jeremy
Member

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 jeremy:ruby24-integer-unification branch 3 times, most recently May 17, 2016

@kaspth

This comment has been minimized.

Member

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

This comment has been minimized.

@sgrif

sgrif May 18, 2016

Member

Didn't the feature mention warning when Fixnumis directly referenced? Should we check for the ruby version explicitly instead?

This comment has been minimized.

@jeremy

jeremy May 18, 2016

Member

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.

This comment has been minimized.

@sgrif

sgrif May 18, 2016

Member

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

This comment has been minimized.

@jeremy

jeremy May 18, 2016

Member

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.

This comment has been minimized.

@sgrif

sgrif May 18, 2016

Member

👍

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

Support for unified Integer class in Ruby 2.4+
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 jeremy:ruby24-integer-unification branch to 89e2f7e May 19, 2016

@jeremy jeremy merged commit 89e2f7e into rails:master May 19, 2016

0 of 2 checks passed

continuous-integration/travis-ci/pr The Travis CI build is in progress
Details
continuous-integration/travis-ci/push The Travis CI build is in progress
Details

@jeremy jeremy deleted the jeremy:ruby24-integer-unification branch May 19, 2016

@jeremy jeremy added this to the 5.0.1 milestone May 19, 2016

@jeremy

This comment has been minimized.

Member

jeremy commented May 19, 2016

5-0-stable: dd7d5b7

@vipulnsward

This comment has been minimized.

Member

vipulnsward commented May 19, 2016

@jeremy needs a CHANGELOG?

@jeremy

This comment has been minimized.

Member

jeremy commented May 19, 2016

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

@vipulnsward

This comment has been minimized.

Member

vipulnsward commented May 19, 2016

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

@rafaelfranca

This comment has been minimized.

Member

rafaelfranca commented May 19, 2016

👍

aliuk2012 added a commit to ministryofjustice/correspondence_tool_staff that referenced this pull request Oct 9, 2018

updates spec to use Integer instead of Fixnum
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

updates spec to use Integer instead of Fixnum
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