[前][次][番号順一覧][スレッド一覧]

ruby-changes:64560

From: Marcus <ko1@a...>
Date: Thu, 24 Dec 2020 19:38:22 +0900 (JST)
Subject: [ruby-changes:64560] 9f9a389d95 (master): doc/syntax/pattern_matching.rdoc: fix typos, grammar, style

https://git.ruby-lang.org/ruby.git/commit/?id=9f9a389d95

From 9f9a389d95d8a4615b39b196e549e3d5f9d00794 Mon Sep 17 00:00:00 2001
From: Marcus Stollsteimer <sto.mar@w...>
Date: Thu, 24 Dec 2020 11:35:03 +0100
Subject: doc/syntax/pattern_matching.rdoc: fix typos, grammar, style


diff --git a/doc/syntax/pattern_matching.rdoc b/doc/syntax/pattern_matching.rdoc
index 2ab1e3e..9f6954f 100644
--- a/doc/syntax/pattern_matching.rdoc
+++ b/doc/syntax/pattern_matching.rdoc
@@ -17,15 +17,15 @@ Pattern matching in Ruby is implemented with the +case+/+in+ expression: https://github.com/ruby/ruby/blob/trunk/doc/syntax/pattern_matching.rdoc#L17
 
 (Note that +in+ and +when+ branches can NOT be mixed in one +case+ expression.)
 
-or with the <code>=></code> operator and the +in+ operator, which can be used in a standalone expression:
+Or with the <code>=></code> operator and the +in+ operator, which can be used in a standalone expression:
 
     <expression> => <pattern>
 
     <expression> in <pattern>
 
-The +case+/+in+ expression is _exhaustive_: if the value of the expression doesn't match any branch of +case+ expression (and +else+ branch is absent), +NoMatchingPatternError+ is raised.
+The +case+/+in+ expression is _exhaustive_: if the value of the expression does not match any branch of the +case+ expression (and the +else+ branch is absent), +NoMatchingPatternError+ is raised.
 
-Therefore, +case+ expression might be used for conditional matching and unpacking:
+Therefore, the +case+ expression might be used for conditional matching and unpacking:
 
   config = {db: {user: 'admin', password: 'abc123'}}
 
@@ -39,7 +39,7 @@ Therefore, +case+ expression might be used for conditional matching and unpackin https://github.com/ruby/ruby/blob/trunk/doc/syntax/pattern_matching.rdoc#L39
   end
   # Prints: "Connect with user 'admin'"
 
-whilst the <code>=></code> operator is most useful when expected data structure is known beforehand, to just unpack parts of it:
+whilst the <code>=></code> operator is most useful when the expected data structure is known beforehand, to just unpack parts of it:
 
   config = {db: {user: 'admin', password: 'abc123'}}
 
@@ -52,7 +52,7 @@ whilst the <code>=></code> operator is most useful when expected data structure https://github.com/ruby/ruby/blob/trunk/doc/syntax/pattern_matching.rdoc#L52
 You can use it when you only want to know if a pattern has been matched or not:
 
   users = [{name: "Alice", age: 12}, {name: "Bob", age: 23}]
-  users.any? {|u| u in {name: /B/, age: 20..} } #=> true
+  users.any? {|user| user in {name: /B/, age: 20..} } #=> true
 
 See below for more examples and explanations of the syntax.
 
@@ -60,7 +60,7 @@ See below for more examples and explanations of the syntax. https://github.com/ruby/ruby/blob/trunk/doc/syntax/pattern_matching.rdoc#L60
 
 Patterns can be:
 
-* any Ruby object (matched by <code>===</code> operator, like in +when+); (<em>Value pattern</em>)
+* any Ruby object (matched by the <code>===</code> operator, like in +when+); (<em>Value pattern</em>)
 * array pattern: <code>[<subpattern>, <subpattern>, <subpattern>, ...]</code>; (<em>Array pattern</em>)
 * find pattern: <code>[*variable, <subpattern>, <subpattern>, <subpattern>, ..., *variable]</code>; (<em>Find pattern</em>)
 * hash pattern: <code>{key: <subpattern>, key: <subpattern>, ...}</code>; (<em>Hash pattern</em>)
@@ -72,7 +72,7 @@ Any pattern can be nested inside array/find/hash patterns where <code><subpatter https://github.com/ruby/ruby/blob/trunk/doc/syntax/pattern_matching.rdoc#L72
 Array patterns and find patterns match arrays, or objects that respond to +deconstruct+ (see below about the latter).
 Hash patterns match hashes, or objects that respond to +deconstruct_keys+ (see below about the latter). Note that only symbol keys are supported for hash patterns.
 
-An important difference between array and hash patterns behavior is arrays match only a _whole_ array
+An important difference between array and hash pattern behavior is that arrays match only a _whole_ array:
 
   case [1, 2, 3]
   in [Integer, Integer]
@@ -82,7 +82,7 @@ An important difference between array and hash patterns behavior is arrays match https://github.com/ruby/ruby/blob/trunk/doc/syntax/pattern_matching.rdoc#L82
   end
   #=> "not matched"
 
-while the hash matches even if there are other keys besides specified part:
+while the hash matches even if there are other keys besides the specified part:
 
   case {a: 1, b: 2, c: 3}
   in {a: Integer}
@@ -92,7 +92,7 @@ while the hash matches even if there are other keys besides specified part: https://github.com/ruby/ruby/blob/trunk/doc/syntax/pattern_matching.rdoc#L92
   end
   #=> "matched"
 
-<code>{}</code> is the only exclusion from this rule. It matches iff an empty hash is given:
+<code>{}</code> is the only exclusion from this rule. It matches only if an empty hash is given:
 
   case {a: 1, b: 2, c: 3}
   in {}
@@ -110,7 +110,7 @@ while the hash matches even if there are other keys besides specified part: https://github.com/ruby/ruby/blob/trunk/doc/syntax/pattern_matching.rdoc#L110
   end
   #=> "matched"
 
-There is also a way to specify there should be no other keys in the matched hash except those explicitly specified by pattern, with <code>**nil</code>:
+There is also a way to specify there should be no other keys in the matched hash except those explicitly specified by the pattern, with <code>**nil</code>:
 
   case {a: 1, b: 2}
   in {a: Integer, **nil} # this will not match the pattern having keys other than a:
@@ -140,7 +140,7 @@ Both array and hash patterns support "rest" specification: https://github.com/ruby/ruby/blob/trunk/doc/syntax/pattern_matching.rdoc#L140
   end
   #=> "matched"
 
-In +case+ (but not in <code>=></code> and +in+) expression, parentheses around both kinds of patterns could be omitted:
+In +case+ (but not in <code>=></code> and +in+) expressions, parentheses around both kinds of patterns could be omitted:
 
   case [1, 2]
   in Integer, Integer
@@ -169,7 +169,7 @@ Find pattern is similar to array pattern but it can be used to check if the give https://github.com/ruby/ruby/blob/trunk/doc/syntax/pattern_matching.rdoc#L169
 
 == Variable binding
 
-Besides deep structural checks, one of the very important features of the pattern matching is the binding of the matched parts to local variables. The basic form of binding is just specifying <code>=> variable_name</code> after the matched (sub)pattern (one might find this similar to storing exceptions in local variables in <code>rescue ExceptionClass => var</code> clause):
+Besides deep structural checks, one of the very important features of the pattern matching is the binding of the matched parts to local variables. The basic form of binding is just specifying <code>=> variable_name</code> after the matched (sub)pattern (one might find this similar to storing exceptions in local variables in a <code>rescue ExceptionClass => var</code> clause):
 
   case [1, 2]
   in Integer => a, Integer
@@ -187,7 +187,7 @@ Besides deep structural checks, one of the very important features of the patter https://github.com/ruby/ruby/blob/trunk/doc/syntax/pattern_matching.rdoc#L187
   end
   #=> "matched: 1"
 
-If no additional check is required, only binding some part of the data to a variable, a simpler form could be used:
+If no additional check is required, for only binding some part of the data to a variable, a simpler form could be used:
 
   case [1, 2]
   in a, Integer
@@ -263,11 +263,11 @@ Variables that start with <code>_</code> are the only exclusions from this rule: https://github.com/ruby/ruby/blob/trunk/doc/syntax/pattern_matching.rdoc#L263
   end
   # => "matched: 1, 2"
 
-It is, though, not advised to reuse bound value, as these pattern's goal is to signify discarded value.
+It is, though, not advised to reuse the bound value, as this pattern's goal is to signify a discarded value.
 
 == Variable pinning
 
-Due to variable binding feature, existing local variable can't be straightforwardly used as a sub-pattern:
+Due to the variable binding feature, existing local variable can not be straightforwardly used as a sub-pattern:
 
   expectation = 18
 
@@ -280,7 +280,7 @@ Due to variable binding feature, existing local variable can't be straightforwar https://github.com/ruby/ruby/blob/trunk/doc/syntax/pattern_matching.rdoc#L280
   # expected: "not matched. expectation was: 18"
   # real: "matched. expectation was: 1" -- local variable just rewritten
 
-For this case, the pin operator <code>^</code> can be used, to tell Ruby "just use this value as a part of pattern":
+For this case, the pin operator <code>^</code> can be used, to tell Ruby "just use this value as part of the pattern":
 
   expectation = 18
   case [1, 2]
@@ -291,7 +291,7 @@ For this case, the pin operator <code>^</code> can be used, to tell Ruby "just u https://github.com/ruby/ruby/blob/trunk/doc/syntax/pattern_matching.rdoc#L291
   end
   #=> "not matched. expectation was: 18"
 
-One important usage of variable pinning is specifying the same value should happen in the pattern several times:
+One important usage of variable pinning is specifying that the same value should occur in the pattern several times:
 
   jane = {school: 'high', schools: [{id: 1, level: 'middle'}, {id: 2, level: 'high'}]}
   john = {school: 'high', schools: [{id: 1, level: 'middle'}]}
@@ -314,7 +314,7 @@ One important usage of variable pinning is specifying the same value should happ https://github.com/ruby/ruby/blob/trunk/doc/syntax/pattern_matching.rdoc#L314
 
 == Matching non-primitive objects: +deconstruct+ and +deconstruct_keys+
 
-As already mentioned above, array/find and hash patterns besides literal arrays and hashes will try to match any object implementing +deconstruct+ (for array/find patterns) or +deconstruct_keys+ (for hash patterns).
+As already mentioned above, array, find, and hash patterns besides literal arrays and hashes will try to match any object implementing +deconstruct+ (for array/find pat (... truncated)

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]