8000 Suppress an integer unification warning for Ruby 2.4.0+ by koic · Pull Request #512 · hashie/hashie · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Suppress an integer unification warning for Ruby 2.4.0+ #512

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

Merged

Conversation

koic
Copy link
Contributor
@koic koic commented Jan 15, 2020

This PR suppresss the following integer unification warning for using Ruby 2.4.0+

% ruby -v
ruby 2.4.9p362 (2019-10-02 revision 67824) [x86_64-darwin17]
% bundle exec rspec spec/hashie/extensions/deep_merge_spec.rb

Hashie::Extensions::DeepMerge
/Users/koic/src/github.com/hahie/hashie/lib/hashie/utils.rb:38: warning:
constant ::Fixnum is deprecated
/Users/koic/src/github.com/hahie/hashie/lib/hashie/utils.rb:38: warning:
constant ::Bignum is deprecated

This PR makes the following change to the product code:

diff --git a/lib/hashie/utils.rb b/lib/hashie/utils.rb
index 5b55b9a..a1365f8 100644
--- a/lib/hashie/utils.rb
+++ b/lib/hashie/utils.rb
@@ -21,24 +21,11 @@ module Hashie
     # @return [Object] the duplicated value
     def self.safe_dup(value)
       case value
-      when Complex, FalseClass, NilClass, Rational, Method, Symbol, TrueClass, *integer_classes
+      when Complex, FalseClass, NilClass, Rational, Method, Symbol, TrueClass, Integer
         value
       else
         value.dup
       end
     end
-
-    # Lists the classes Ruby uses for integers
-    #
-    # @api private
-    # @return [Array<Class>]
-    def self.integer_classes
-      @integer_classes ||=
-        if const_defined?(:Fixnum)
-          [Fixnum, Bignum] # rubocop:disable Lint/UnifiedInteger
-        else
-          [Integer]
-        end
-    end
   end
 end

This change that uses Integer instead of Fixnum and Bignum in case ... when statement is compatible with Ruby 2.3 and lower.

% ruby -v
ruby 2.3.8p459 (2018-10-18 revision 65136) [x86_64-darwin17]

42.class          #=> Fixnum
42.is_a?(Integer) #=> true

case 42
when Fixnum
  true
else
  false
end               #=> true

case 42
when Integer
  true
else
  false
end               #=> true

Bignum has the same behavior as Fixnum because it inherits Integer.

@koic koic changed the title Suppress an integer unification warning for using Ruby 2.4.0+ Suppress an integer unification warning for Ruby 2.4.0+ Jan 15, 2020
@koic koic force-pushed the suppress_integer_unification_warning_for_ruby_2_4_0 branch from e8be3ca to d80b83a Compare January 15, 2020 05:48
@dblock
Copy link
Member
dblock commented Jan 15, 2020

What are the implications/side effects of this? We are breaking compatibility with an older version of Ruby? Can we please double-check that we (have) state(d) what we're now compatible with? +rebase

@koic koic force-pushed the suppress_integer_unification_warning_for_ruby_2_4_0 branch from d80b83a to 259734a Compare January 16, 2020 01:52
This PR suppresss the following integer unification warning
for Ruby 2.4.0+

```console
% ruby -v
ruby 2.4.9p362 (2019-10-02 revision 67824) [x86_64-darwin17]
% bundle exec rspec spec/hashie/extensions/deep_merge_spec.rb

Hashie::Extensions::DeepMerge
/Users/koic/src/github.com/hahie/hashie/lib/hashie/utils.rb:38: warning:
constant ::Fixnum is deprecated
/Users/koic/src/github.com/hahie/hashie/lib/hashie/utils.rb:38: warning:
constant ::Bignum is deprecated
```
@koic koic force-pushed the suppress_integer_unification_warning_for_ruby_2_4_0 branch from 259734a to 4d3d062 Compare January 16, 2020 02:05
@koic
Copy link
Contributor Author
koic commented Jan 16, 2020

Thanks for your review. I updated the PR with more safe change. It uses the approach used by Rails framework.
https://github.com/rails/rails/blob/v5.2.4.1/activesupport/lib/active_support/xml_mini.rb#L52-L54

@dblock dblock merged commit 7fa93b1 into hashie:master Jan 16, 2020
@dblock
Copy link
Member
dblock commented Jan 16, 2020

👍

@koic koic deleted the suppress_integer_unification_warning_for_ruby_2_4_0 branch January 16, 2020 14:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0