From ce0f3de032ea0dffbfd20dfbfe33453f65ec5a7c Mon Sep 17 00:00:00 2001 From: zverok Date: Wed, 15 Feb 2023 22:42:22 +0200 Subject: [DOC] Update pattern matching docs for 3.2 * Remove section about experimental status * Add references to core objects that can deconstruct --- doc/syntax/pattern_matching.rdoc | 28 +++++----------------------- 1 file changed, 5 insertions(+), 23 deletions(-) (limited to 'doc') diff --git a/doc/syntax/pattern_matching.rdoc b/doc/syntax/pattern_matching.rdoc index b7d614770c..e49c09a1f8 100644 --- a/doc/syntax/pattern_matching.rdoc +++ b/doc/syntax/pattern_matching.rdoc @@ -415,6 +415,11 @@ Additionally, when matching custom classes, the expected class can be specified end #=> "matched: 1" +These core and library classes implement deconstruction: + +* MatchData#deconstruct and MatchData#deconstruct_keys; +* Time#deconstruct_keys, Date#deconstruct_keys, DateTime#deconstruct_keys. + == Guard clauses +if+ can be used to attach an additional condition (guard clause) when the pattern matches. This condition may use bound variables: @@ -445,29 +450,6 @@ Additionally, when matching custom classes, the expected class can be specified end #=> "matched" -== Current feature status - -As of Ruby 3.1, find patterns are considered _experimental_: its syntax can change in the future. Every time you use these features in code, a warning will be printed: - - [0] => [*, 0, *] - # warning: Find pattern is experimental, and the behavior may change in future versions of Ruby! - # warning: One-line pattern matching is experimental, and the behavior may change in future versions of Ruby! - -To suppress this warning, one may use the Warning::[]= method: - - Warning[:experimental] = false - eval('[0] => [*, 0, *]') - # ...no warning printed... - -Note that pattern-matching warnings are raised at compile time, so this will not suppress the warning: - - Warning[:experimental] = false # At the time this line is evaluated, the parsing happened and warning emitted - [0] => [*, 0, *] - -So, only subsequently loaded files or `eval`-ed code is affected by switching the flag. - -Alternatively, the command line option -W:no-experimental can be used to turn off "experimental" feature warnings. - == Appendix A. Pattern syntax Approximate syntax is: -- cgit v1.2.1