You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.adoc
+9-7
Original file line number
Diff line number
Diff line change
@@ -1422,10 +1422,12 @@ end
1422
1422
1423
1423
=== `and`/`or` [[no-and-or-or]] [[and-or-flow]]
1424
1424
1425
-
`and` and `or` are control flow operators. They have very low precedence, and can be used as a short
1426
-
form of specifying flow sequences like "evaluate expression 1, and only if it is not successful
1427
-
(returned `nil`), evaluate expression 2". This is especially useful for raising errors or early
1428
-
return without breaking the reading flow.
1425
+
Do not use `and` and `or` in boolean context - `and` and `or` are control flow
1426
+
operators and should be used as such. They have very low precedence, and can be
1427
+
used as a short form of specifying flow sequences like "evaluate expression 1,
1428
+
and only if it is not successful (returned `nil`), evaluate expression 2". This
1429
+
is especially useful for raising errors or early return without breaking the
1430
+
reading flow.
1429
1431
1430
1432
[source,ruby]
1431
1433
----
@@ -1454,8 +1456,8 @@ ok = got_needed_arguments && arguments_valid
1454
1456
x = extract_arguments || raise(ArgumentError, "Not enough arguments!")
1455
1457
----
1456
1458
1457
-
But avoid several control flow operators in one expression, that becomes
1458
-
confusing:
1459
+
But avoid several control flow operators in one expression, as that quickly
1460
+
becomes confusing:
1459
1461
1460
1462
[source,ruby]
1461
1463
----
@@ -1478,7 +1480,7 @@ if x
1478
1480
end
1479
1481
---
1480
1482
1481
-
NOTE: Whether organizing control flow with `and` and `or` is a good idea was a controversial topic in the community for a long time. But if you do, prefer these operators over `&&`/`||`.
1483
+
NOTE: Whether organizing control flow with `and` and `or` is a good idea has been a controversial topic in the community for a long time. But if you do, prefer these operators over `&&`/`||`.
0 commit comments