summaryrefslogtreecommitdiff
path: root/doc/syntax/pattern_matching.rdoc
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2024-05-12 16:23:00 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2024-05-12 16:23:00 +0900
commitb911d2222f907d3fad397938e8f513ecfb4635b8 (patch)
tree4b1dbb09896ae3ceb454d34a7532043ed898ad56 /doc/syntax/pattern_matching.rdoc
parent5695c5df95460ed9949e1c8f8ca89b4a5c5cc4dd (diff)
[Bug #20482] [DOC] Clarify about pattern maching guard clause
Guard clauses can only be used in `case` pattern matching statements, not in `=>`/`in` operators.
Diffstat (limited to 'doc/syntax/pattern_matching.rdoc')
-rw-r--r--doc/syntax/pattern_matching.rdoc8
1 files changed, 7 insertions, 1 deletions
diff --git a/doc/syntax/pattern_matching.rdoc b/doc/syntax/pattern_matching.rdoc
index e49c09a1f8..6a30380f46 100644
--- a/doc/syntax/pattern_matching.rdoc
+++ b/doc/syntax/pattern_matching.rdoc
@@ -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: