@@ -3523,8 +3523,8 @@ Person.ancestors
35233523| 0.92
35243524|===
35253525
3526- Checks for consistent usage of the `DateTime ` class over the
3527- `Time ` class. This cop is disabled by default since these classes,
3526+ Checks for consistent usage of the `Time ` class over the
3527+ `DateTime ` class. This cop is disabled by default since these classes,
35283528although highly overlapping, have particularities that make them not
35293529replaceable in certain situations when dealing with multiple timezones
35303530and/or DST.
@@ -10801,6 +10801,12 @@ instance methods in the module, then check if a given method is inside that
1080110801array, while `method_defined?` will do direct method lookup, which is much
1080210802faster and consumes less memory.
1080310803
10804+ NOTE: `constants.include?` is not handled by this cop because
10805+ `Module#const_defined?` has different lookup behavior than
10806+ `Module#constants` - `const_defined?` searches up to `Object`
10807+ (top-level constants like `String`, `Integer`, etc.) while
10808+ `constants` does not, which can cause behavior changes after autocorrection.
10809+
1080410810[#examples-stylemodulememberexistencecheck]
1080510811=== Examples
1080610812
@@ -10820,14 +10826,12 @@ Array.method_defined?(:find, false)
1082010826
1082110827# bad
1082210828Array.class_variables.include?(:foo)
10823- Array.constants.include?(:foo)
1082410829Array.private_instance_methods.include?(:foo)
1082510830Array.protected_instance_methods.include?(:foo)
1082610831Array.public_instance_methods.include?(:foo)
1082710832
1082810833# good
1082910834Array.class_variable_defined?(:foo)
10830- Array.const_defined?(:foo)
1083110835Array.private_method_defined?(:foo)
1083210836Array.protected_method_defined?(:foo)
1083310837Array.public_method_defined?(:foo)
@@ -20591,6 +20595,11 @@ end
2059120595# good
2059220596x += 1 while x < 10
2059320597
20598+ # good
20599+ while x < 10
20600+ y += 1 if x.odd?
20601+ end
20602+
2059420603# bad
2059520604until x > 10
2059620605 x += 1
@@ -20599,6 +20608,11 @@ end
2059920608# good
2060020609x += 1 until x > 10
2060120610
20611+ # good
20612+ until x > 10
20613+ y += 1 unless x.even?
20614+ end
20615+
2060220616# bad
2060320617x += 100 while x < 500 # a long comment that makes code too long if it were a single line
2060420618
0 commit comments