Class: Rubocop::Cop::NestedTernaryOperator

Inherits:
Cop
  • Object
show all
Includes:
TernaryOperator
Defined in:
lib/rubocop/cop/ternary_operator.rb

Instance Attribute Summary

Attributes inherited from Cop

#correlations, #offences

Instance Method Summary collapse

Methods included from TernaryOperator

#inspect

Methods inherited from Cop

#add_offence, #has_report?, inherited, #initialize

Constructor Details

This class inherits a constructor from Rubocop::Cop::Cop

Instance Method Details

#error_messageObject



31
32
33
34
# File 'lib/rubocop/cop/ternary_operator.rb', line 31

def error_message
  'Ternary operators must not be nested. Prefer if/else constructs ' +
    'instead.'
end

#offends?(ifop) ⇒ Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/rubocop/cop/ternary_operator.rb', line 36

def offends?(ifop)
  ifop.flatten[1..-1].include?(:ifop)
end