Class: Nitpick::Warnings::UselessBranch

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from SimpleWarning

#==, discover

Constructor Details

#initialize(*args) ⇒ UselessBranch

Returns a new instance of UselessBranch.



6
7
8
# File 'lib/nitpick/warnings/useless_branch.rb', line 6

def initialize(*args)
  @cond, @yes_branch, @no_branch = args
end

Instance Attribute Details

#no_branchObject (readonly)

Returns the value of attribute no_branch.



4
5
6
# File 'lib/nitpick/warnings/useless_branch.rb', line 4

def no_branch
  @no_branch
end

#yes_branchObject (readonly)

Returns the value of attribute yes_branch.



4
5
6
# File 'lib/nitpick/warnings/useless_branch.rb', line 4

def yes_branch
  @yes_branch
end

Instance Method Details

#matches?Boolean

Returns:

  • (Boolean)


10
11
12
13
# File 'lib/nitpick/warnings/useless_branch.rb', line 10

def matches?
  (yes_branch == s(:true) and no_branch == s(:false)) or
    (yes_branch == s(:false) and no_branch == s(:true))
end

#messageObject



15
16
17
# File 'lib/nitpick/warnings/useless_branch.rb', line 15

def message
  "No need for an if. Just return '#{sexp_to_ruby(@cond)}' as a boolean."
end