Class: Nitpick::Warnings::AssignmentAsCondition

Inherits:
SimpleWarning show all
Defined in:
lib/nitpick/warnings/assignment_as_condition.rb

Constant Summary collapse

ASSIGNMENT_NODES =
[:lasgn, :op_asgn_or, :op_asgn_and, :iasgn,
:op_asgn1, :gasgn, :dasgn_curr]

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from SimpleWarning

#==, discover

Constructor Details

#initialize(*args) ⇒ AssignmentAsCondition

Returns a new instance of AssignmentAsCondition.



9
10
11
# File 'lib/nitpick/warnings/assignment_as_condition.rb', line 9

def initialize(*args)
  @condition = args.shift
end

Instance Attribute Details

#conditionObject (readonly)

Returns the value of attribute condition.



7
8
9
# File 'lib/nitpick/warnings/assignment_as_condition.rb', line 7

def condition
  @condition
end

Instance Method Details

#matches?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/nitpick/warnings/assignment_as_condition.rb', line 13

def matches?
  ASSIGNMENT_NODES.include? @condition.first
end

#messageObject



17
18
19
# File 'lib/nitpick/warnings/assignment_as_condition.rb', line 17

def message
  "An assigment is being used as a condition: (#{sexp_to_ruby(@condition)})"
end