Skip to content

Latest commit

 

History

History
47 lines (33 loc) · 1.1 KB

Repeated-Conditional.md

File metadata and controls

47 lines (33 loc) · 1.1 KB

Repeated Conditional

Introduction

Repeated Conditional is a case of Simulated Polymorphism. Basically it means you are checking the same value throughout a single class and take decisions based on this.

Example

Given

class RepeatedConditionals
  attr_accessor :switch

  def repeat_1
    puts "Repeat 1!" if switch
  end

  def repeat_2
    puts "Repeat 2!" if switch
  end

  def repeat_3
    puts "Repeat 3!" if switch
  end
end

Reek would emit the following warning:

test.rb -- 4 warnings:
  [5, 9, 13]:RepeatedConditionals tests switch at least 3 times (RepeatedConditional)

If you get this warning then you are probably not using the right abstraction or even more probable, missing an additional abstraction.

Configuration

Reek's Repeated Conditional detector offers the Basic Smell Options, plus:

Option Value Effect
max_ifs integer The maximum number of identical conditional tests permitted before Reek raises a warning. Defaults to 2.