Rubocop: InverseMethods false positive for Module#<,>,>=,<=

Created on 2 Mar 2018  路  3Comments  路  Source: rubocop-hq/rubocop

Hi!

I've just faced an offence with code: !(klass < BaseClass) which checks that class from variable is not a subclass of BaseClass. Here is the message:

RuboCop: Style/InverseMethods: Use `>` instead of inverting `<=`

I've checked issues but have not found related. I think there is no way to make this cop handle correctly Number#< and Module#<. WDYT?

PS. in this particular case it was ok for me to switch to <=>, because it's guaranteed that klass can not be superclass of BaseClass.

Most helpful comment

I keep learning new things about Ruby after all those years - I was always using the ancestors method. 馃槃

All 3 comments

Style/InverseMethods could be changed to suppress offenses when one of the operands looks like a class or module (capital first letter, but not all-caps).

I keep learning new things about Ruby after all those years - I was always using the ancestors method. 馃槃

Matz:

You shouldn't really be doing type checks in Ruby.

Also Matz:

Let's add some zany facilities for advanced type checking.

馃槄

Was this page helpful?
0 / 5 - 0 ratings

Related issues

AndreiMotinga picture AndreiMotinga  路  3Comments

kirrmann picture kirrmann  路  3Comments

joromir picture joromir  路  3Comments

benoittgt picture benoittgt  路  3Comments

NobodysNightmare picture NobodysNightmare  路  3Comments