Skip to content

Commit bd6f8a2

Browse files
dpisarewskibbatsov
authored andcommitted
Add a type-checking rule for integer numbers (rubocop#564)
1 parent c0e3a69 commit bd6f8a2

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

README.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ Translations of the guide are available in the following languages:
8787
* [Classes & Modules](#classes--modules)
8888
* [Exceptions](#exceptions)
8989
* [Collections](#collections)
90+
* [Numbers](#numbers)
9091
* [Strings](#strings)
9192
* [Regular Expressions](#regular-expressions)
9293
* [Percent Literals](#percent-literals)
@@ -1512,7 +1513,7 @@ condition](#safe-assignment-in-condition).
15121513

15131514
# good
15141515
'ruby' == some_str
1515-
1.0.eql? x # eql? makes sense here if want to differentiate between Fixnum and Float 1
1516+
1.0.eql? x # eql? makes sense here if want to differentiate between Integer and Float 1
15161517
```
15171518

15181519
* <a name="no-cryptic-perlisms"></a>
@@ -3300,6 +3301,23 @@ resource cleanup when possible.
33003301
end
33013302
end
33023303
```
3304+
## Numbers
3305+
3306+
* <a name="integer-type-checking"></a>
3307+
Use `Integer` check type of an integer number. Since `Fixnum` is platform-dependent, checking against it will
3308+
return different results on 32-bit and 64-bit machines.
3309+
<sup>[[link](#integer-type-checking)]</sup>
3310+
3311+
```Ruby
3312+
timestamp = Time.now.to_i
3313+
3314+
# bad
3315+
timestamp.is_a? Fixnum
3316+
timestamp.is_a? Bignum
3317+
3318+
# good
3319+
timestamp.is_a? Integer
3320+
```
33033321

33043322
## Strings
33053323

0 commit comments

Comments
 (0)