30 lines
547 B
Plaintext
30 lines
547 B
Plaintext
![]() |
If the same logic is needed for both instances, then:
|
||
|
|
||
|
* in an `if` structure they should be combined
|
||
|
|
||
|
[source,ruby,diff-id=1,diff-type=compliant]
|
||
|
----
|
||
|
if (a >= 0 && a < 10) || (a >= 20 && a < 50)
|
||
|
doFirstThing()
|
||
|
doTheThing()
|
||
|
elsif a >= 10 && a < 20
|
||
|
doTheOtherThing()
|
||
|
else
|
||
|
doTheRest()
|
||
|
end
|
||
|
----
|
||
|
|
||
|
* for a `case`, the values should be put in the `when` expression list.
|
||
|
|
||
|
[source,ruby,diff-id=2,diff-type=compliant]
|
||
|
----
|
||
|
case i
|
||
|
when 1, 3
|
||
|
doFirstThing()
|
||
|
doSomething()
|
||
|
when 2
|
||
|
doSomethingDifferent()
|
||
|
else
|
||
|
doTheRest()
|
||
|
end
|
||
|
----
|