Sha256: eedcef5c7adc41497840c2619a1545e2275e8ef122b602cc716368220eeb7c26

Contents?: true

Size: 1.1 KB

Versions: 53

Compression:

Stored size: 1.1 KB

Contents

# Repeated Conditional

## Introduction

_Repeated Conditional_ is a case of
[Simulated Polymorphism](Simulated-Polymorphism.md). Basically it means you are
checking the same value throughout a single class and take decisions based on
this.

## Example

Given

```Ruby
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](Basic-Smell-Options.md), plus:

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

Version data entries

53 entries across 51 versions & 2 rubygems

Version Path
reek-6.0.3 docs/Repeated-Conditional.md
reek-6.0.2 docs/Repeated-Conditional.md
reek-6.0.1 docs/Repeated-Conditional.md
reek-6.0.0 docs/Repeated-Conditional.md
reek-5.6.0 docs/Repeated-Conditional.md
reek-5.5.0 docs/Repeated-Conditional.md
reek-5.4.1 docs/Repeated-Conditional.md
reek-5.4.0 docs/Repeated-Conditional.md
reek-5.3.2 docs/Repeated-Conditional.md
reek-5.3.1 docs/Repeated-Conditional.md
reek-5.3.0 docs/Repeated-Conditional.md
config_gems_initialization_aim-0.1.4 vendor/bundle/ruby/2.5.0/gems/config_gems_initialization_aim-0.1.1/vendor/bundle/ruby/2.5.0/gems/reek-5.2.0/docs/Repeated-Conditional.md
config_gems_initialization_aim-0.1.4 vendor/bundle/ruby/2.5.0/gems/reek-5.2.0/docs/Repeated-Conditional.md
config_gems_initialization_aim-0.1.3 vendor/bundle/ruby/2.5.0/gems/config_gems_initialization_aim-0.1.1/vendor/bundle/ruby/2.5.0/gems/reek-5.2.0/docs/Repeated-Conditional.md
config_gems_initialization_aim-0.1.3 vendor/bundle/ruby/2.5.0/gems/reek-5.2.0/docs/Repeated-Conditional.md
reek-5.2.0 docs/Repeated-Conditional.md
reek-5.1.0 docs/Repeated-Conditional.md
reek-5.0.2 docs/Repeated-Conditional.md
reek-5.0.1 docs/Repeated-Conditional.md
reek-5.0.0 docs/Repeated-Conditional.md