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, #on_comment

Constructor Details

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

Instance Method Details

#error_messageObject



60
61
62
# File 'lib/rubocop/cop/if_then_else.rb', line 60

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

#offending_line(node) ⇒ Object



56
57
58
# File 'lib/rubocop/cop/if_then_else.rb', line 56

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