ruby-changes:59344
From: Yusuke <ko1@a...>
Date: Fri, 20 Dec 2019 21:39:15 +0900 (JST)
Subject: [ruby-changes:59344] 1fea3a7636 (master): NEWS: Update the explanation of pattern matching
https://git.ruby-lang.org/ruby.git/commit/?id=1fea3a7636 From 1fea3a7636cfaf25baba1e9f208c68a8a8ba52cc Mon Sep 17 00:00:00 2001 From: Yusuke Endoh <mame@r...> Date: Fri, 20 Dec 2019 21:37:46 +0900 Subject: NEWS: Update the explanation of pattern matching Add an example of "<expr> in <pattern>", an example of NoMatchingPatternError, and mention that the slides are slightly obsolete. diff --git a/NEWS b/NEWS index e0efad8..a67d16b 100644 --- a/NEWS +++ b/NEWS @@ -32,6 +32,11 @@ sufficient information, see the ChangeLog file or Redmine https://github.com/ruby/ruby/blob/trunk/NEWS#L32 p var #=> 1 end + case -1 + in 0 then :unreachable + in 1 then :unreachable + end #=> NoMatchingPatternError + json = <<END { "name": "Alice", @@ -39,13 +44,18 @@ sufficient information, see the ChangeLog file or Redmine https://github.com/ruby/ruby/blob/trunk/NEWS#L44 "children": [{ "name": "Bob", "age": 2 }] } END - case JSON.parse(json, symbolize_names: true) - in {name: "Alice", children: [{name: "Bob", age: age}]} - p age #=> 2 - end + + JSON.parse(json, symbolize_names: true) in {name: "Alice", children: [{name: name, age: age}]} + + p name #=> "Bob" + p age #=> 2 + + JSON.parse(json, symbolize_names: true) in {name: "Alice", children: [{name: "Charlie", age: age}]} + #=> NoMatchingPatternError * See the following slides in detail * https://speakerdeck.com/k_tsj/pattern-matching-new-feature-in-ruby-2-dot-7 + * Note that the slides are slightly obsolete ==== The spec of keyword arguments is changed towards 3.0 -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/