Class: Rubocop::Cop::OneLineConditional

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

Instance Attribute Summary

Attributes inherited from Cop

#debug, #disabled_lines, #offences

Instance Method Summary collapse

Methods included from IfThenElse

#check, #on_if, #on_unless

Methods inherited from Cop

#add_offence, cop_name, #has_report?, #ignore_node, inherited, #initialize, #inspect, #name

Constructor Details

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

Instance Method Details

#error_messageObject



70
71
72
# File 'lib/rubocop/cop/if_then_else.rb', line 70

def error_message
  'Favor the ternary operator (?:) over if/then/else/end constructs.'
end

#offending_line(node) ⇒ Object



66
67
68
# File 'lib/rubocop/cop/if_then_else.rb', line 66

def offending_line(node)
  node.loc.expression.line unless node.loc.expression.source =~ /\n/
end