1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Allow omission of parentheses in one line pattern matching [Feature #16182]

This commit is contained in:
Kazuki Tsujimoto 2021-08-19 17:03:17 +09:00
parent 00d66f7ec2
commit ecb6d6a4ef
No known key found for this signature in database
GPG key ID: BCEA306C49B81CD7
4 changed files with 27 additions and 10 deletions

View file

@ -140,7 +140,7 @@ Both array and hash patterns support "rest" specification:
end
#=> "matched"
In +case+ (but not in <code>=></code> and +in+) expressions, parentheses around both kinds of patterns could be omitted:
Parentheses around both kinds of patterns could be omitted:
case [1, 2]
in Integer, Integer
@ -158,6 +158,12 @@ In +case+ (but not in <code>=></code> and +in+) expressions, parentheses around
end
#=> "matched"
[1, 2] => a, b
[1, 2] in a, b
{a: 1, b: 2, c: 3} => a:
{a: 1, b: 2, c: 3} in a:
Find pattern is similar to array pattern but it can be used to check if the given object has any elements that match the pattern:
case ["a", 1, "b", "c", 2]