[Bug #20482] [DOC] Clarify about pattern maching guard clause
authorNobuyoshi Nakada <[email protected]>
Sun, 12 May 2024 07:23:00 +0000 (12 16:23 +0900)
committerNobuyoshi Nakada <[email protected]>
Sun, 12 May 2024 07:23:00 +0000 (12 16:23 +0900)
Guard clauses can only be used in `case` pattern matching statements,
not in `=>`/`in` operators.

doc/syntax/pattern_matching.rdoc

index e49c09a..6a30380 100644 (file)
@@ -422,7 +422,8 @@ These core and library classes implement deconstruction:
 
 == Guard clauses
 
-+if+ can be used to attach an additional condition (guard clause) when the pattern matches. This condition may use bound variables:
++if+ can be used to attach an additional condition (guard clause) when the pattern matches in +case+/+in+ expressions.
+This condition may use bound variables:
 
   case [1, 2]
   in a, b if b == a*2
@@ -450,6 +451,11 @@ These core and library classes implement deconstruction:
   end
   #=> "matched"
 
+Note that <code>=></code> and +in+ operator can not have a guard clause.
+The following examples is parsed as a standalone expression with modifier +if+.
+
+  [1, 2] in a, b if b == a*2
+
 == Appendix A. Pattern syntax
 
 Approximate syntax is: