Any reason your base code can't use Integer alone? If I understand correctly, Ruby will convert a very large number to Bignum if necessary, in older Ruby versions. Take that as from a newbie, and verify.
Leam
···
On 02/20/17 04:33, Samuel Williams wrote:
Hello,
In my code, after migrating to 2.4.0, I see a lot of
gems/mapping-1.0.0/lib/mapping/object_model.rb:26: warning: constant
::Fixnum is deprecated
gems/mapping-1.0.0/lib/mapping/object_model.rb:26: warning: constant
::Bignum is deprecated
This code still works okay, but I was wondering, how should I write my
code now to not produce warnings with both 2.3 and 2.4?
e.g. the code trivially could be something like this:
if RUBY_VERSION < "2.4"
IntegralTypes = [Bignum, Fixnum]
else
IntegralTypes = [Integer]
end
But this seems very ugly.
It's not only my gem this is an issue, it's also present in
active_support/xml_mini.rb
How do you use IntegralTypes in your code?
The "IntegralTypes = [Integer]" should work for <2.4 if you
use .kind_of? instead of exact matching via ".class =="
I normally use one of the following, all of which work in all
Ruby versions:
a) if Integer === foo
...
b) if foo.kind_of?(Integer)
...
c) case foo
when Integer
...
···
Samuel Williams <space.ship.traveller@gmail.com> wrote:
Hello,
In my code, after migrating to 2.4.0, I see a lot of
gems/mapping-1.0.0/lib/mapping/object_model.rb:26: warning: constant
::Fixnum is deprecated
gems/mapping-1.0.0/lib/mapping/object_model.rb:26: warning: constant
::Bignum is deprecated
This code still works okay, but I was wondering, how should I write my
code now to not produce warnings with both 2.3 and 2.4?
e.g. the code trivially could be something like this:
if RUBY_VERSION < "2.4"
IntegralTypes = [Bignum, Fixnum]
else
IntegralTypes = [Integer]
end
On 20 February 2017 at 23:40, Eric Wong <e@80x24.org> wrote:
Samuel Williams <space.ship.traveller@gmail.com> wrote:
Hello,
In my code, after migrating to 2.4.0, I see a lot of
gems/mapping-1.0.0/lib/mapping/object_model.rb:26: warning: constant
::Fixnum is deprecated
gems/mapping-1.0.0/lib/mapping/object_model.rb:26: warning: constant
::Bignum is deprecated
This code still works okay, but I was wondering, how should I write my
code now to not produce warnings with both 2.3 and 2.4?
e.g. the code trivially could be something like this:
if RUBY_VERSION < "2.4"
IntegralTypes = [Bignum, Fixnum]
else
IntegralTypes = [Integer]
end
But this seems very ugly.
How do you use IntegralTypes in your code?
The "IntegralTypes = [Integer]" should work for <2.4 if you
use .kind_of? instead of exact matching via ".class =="
I normally use one of the following, all of which work in all
Ruby versions:
Unless TYPE_NAMES hash is used elsewhere, I don't think they
need to be using that hash... They can use the case/when I
described in c) above.
Calling foo.class.name also generates short-lived garbage
strings if that code path is called frequently. Checking #kind_of? and === (via case/when) won't make garbage.
Anyways I don't use Rails or centralized/proprietary messaging
systems; but maybe somebody who does can rework the code to
be version-independent and generate less garbage at the same
time...
···
Samuel Williams <space.ship.traveller@gmail.com> wrote:
On 20 February 2017 at 23:40, Eric Wong <e@80x24.org> wrote: