From 9e69116cde7ec4ad0212c85493f00cdd171696c0 Mon Sep 17 00:00:00 2001 From: Simon George Date: Mon, 18 Sep 2017 11:23:04 +0100 Subject: [PATCH] Fix Fixnum Bignum deprecation warning Ruby 2.4 unifies Fixnum and Bignum into Integer and prints a warning if the old constants are accessed. hyper-react causes this warning to be printed on boot: ``` lib/reactive-ruby/serializers.rb:1: warning: constant ::Bignum is deprecated lib/reactive-ruby/serializers.rb:1: warning: constant ::Fixnum is deprecated ``` I've fixed this in the [same way as Rails](https://github.com/jeremy/rails/blob/b9bda7fd891147a0bc0cffa6dd9d15601be8b472/activesupport/lib/active_support/core_ext/numeric/conversions.rb#L131) to support both older and newer versions of Ruby. --- lib/reactive-ruby/serializers.rb | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/reactive-ruby/serializers.rb b/lib/reactive-ruby/serializers.rb index b79c759..0ba2fc4 100644 --- a/lib/reactive-ruby/serializers.rb +++ b/lib/reactive-ruby/serializers.rb @@ -1,7 +1,13 @@ -[Bignum, FalseClass, Fixnum, Float, Integer, NilClass, String, Symbol, Time, TrueClass].each do |klass| - klass.send(:define_method, :react_serializer) do - as_json - end +[TrueClass, FalseClass, NilClass, Float, String, Symbol, Time].each do |klass| + klass.send(:define_method, :react_serializer) { as_json } +end +# Ruby 2.4 unifies Fixnum and Bignum into Integer +# and prints a warning if the old constants are accessed. +if 0.class == Integer + Integer.send(:define_method, :react_serializer) { as_json } +else + Fixnum.send(:define_method, :react_serializer) { as_json } + Bignum.send(:define_method, :react_serializer) { as_json } end BigDecimal.send(:define_method, :react_serializer) { as_json } rescue nil