ruby-changes:59580
From: Kazuhiro <ko1@a...>
Date: Wed, 1 Jan 2020 02:04:17 +0900 (JST)
Subject: [ruby-changes:59580] db58b4a48d (master): Update NEWS for Ruby 2.8.0 (tentative; to be 3.0.0)
https://git.ruby-lang.org/ruby.git/commit/?id=db58b4a48d From db58b4a48d7a632550d67a5c8bc4ecc37819d6c9 Mon Sep 17 00:00:00 2001 From: Kazuhiro NISHIYAMA <zn@m...> Date: Tue, 31 Dec 2019 18:18:21 +0900 Subject: Update NEWS for Ruby 2.8.0 (tentative; to be 3.0.0) diff --git a/NEWS b/NEWS index 4ff6cf0..15f5f14 100644 --- a/NEWS +++ b/NEWS @@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/NEWS#L1 # -*- rdoc -*- -= NEWS for Ruby 2.7.0 += NEWS for Ruby 2.8.0 (tentative; to be 3.0.0) This document is a list of user visible feature changes made between releases except for bug fixes. @@ -10,819 +10,22 @@ information is supplied with. For a full list of changes with all https://github.com/ruby/ruby/blob/trunk/NEWS#L10 sufficient information, see the ChangeLog file or Redmine (e.g. <tt>https://bugs.ruby-lang.org/issues/$FEATURE_OR_BUG_NUMBER</tt>). -== Changes since the 2.6.0 release +== Changes since the 2.7.0 release === Language changes -==== Pattern matching - -* Pattern matching is introduced as an experimental feature. [Feature #14912] - - case [0, [1, 2, 3]] - in [a, [b, *c]] - p a #=> 0 - p b #=> 1 - p c #=> [2, 3] - end - - case {a: 0, b: 1} - in {a: 0, x: 1} - :unreachable - in {a: 0, b: var} - p var #=> 1 - end - - case -1 - in 0 then :unreachable - in 1 then :unreachable - end #=> NoMatchingPatternError - - json = <<END - { - "name": "Alice", - "age": 30, - "children": [{ "name": "Bob", "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 for more details: - * https://speakerdeck.com/k_tsj/pattern-matching-new-feature-in-ruby-2-dot-7 - * Note that the slides are slightly obsolete. - -* The warning against pattern matching can be suppressed with - {-W:no-experimental option}[#label-Warning+option]. - -==== The spec of keyword arguments is changed towards 3.0 - -* Automatic conversion of keyword arguments and positional arguments is - deprecated, and conversion will be removed in Ruby 3. [Feature #14183] - - * When a method call passes a Hash at the last argument, and when it - passes no keywords, and when the called method accepts keywords, - a warning is emitted. To continue treating the hash as keywords, - add a double splat operator to avoid the warning and ensure - correct behavior in Ruby 3. - - def foo(key: 42); end; foo({key: 42}) # warned - def foo(**kw); end; foo({key: 42}) # warned - def foo(key: 42); end; foo(**{key: 42}) # OK - def foo(**kw); end; foo(**{key: 42}) # OK - - * When a method call passes keywords to a method that accepts keywords, - but it does not pass enough required positional arguments, the - keywords are treated as a final required positional argument, and a - warning is emitted. Pass the argument as a hash instead of keywords - to avoid the warning and ensure correct behavior in Ruby 3. - - def foo(h, **kw); end; foo(key: 42) # warned - def foo(h, key: 42); end; foo(key: 42) # warned - def foo(h, **kw); end; foo({key: 42}) # OK - def foo(h, key: 42); end; foo({key: 42}) # OK - - * When a method accepts specific keywords but not a keyword splat, and - a hash or keywords splat is passed to the method that includes both - Symbol and non-Symbol keys, the hash will continue to be split, and - a warning will be emitted. You will need to update the calling code - to pass separate hashes to ensure correct behavior in Ruby 3. - - def foo(h={}, key: 42); end; foo("key" => 43, key: 42) # warned - def foo(h={}, key: 42); end; foo({"key" => 43, key: 42}) # warned - def foo(h={}, key: 42); end; foo({"key" => 43}, key: 42) # OK - - * If a method does not accept keywords, and is called with keywords, - the keywords are still treated as a positional hash, with no warning. - This behavior will continue to work in Ruby 3. - - def foo(opt={}); end; foo( key: 42 ) # OK - -* Non-symbols are allowed as keyword argument keys if the method accepts - arbitrary keywords. [Feature #14183] - - * Non-Symbol keys in a keyword arguments hash were prohibited in 2.6.0, - but are now allowed again. [Bug #15658] - - def foo(**kw); p kw; end; foo("str" => 1) #=> {"str"=>1} - -* <code>**nil</code> is allowed in method definitions to explicitly mark - that the method accepts no keywords. Calling such a method with keywords - will result in an ArgumentError. [Feature #14183] - - def foo(h, **nil); end; foo(key: 1) # ArgumentError - def foo(h, **nil); end; foo(**{key: 1}) # ArgumentError - def foo(h, **nil); end; foo("str" => 1) # ArgumentError - def foo(h, **nil); end; foo({key: 1}) # OK - def foo(h, **nil); end; foo({"str" => 1}) # OK - -* Passing an empty keyword splat to a method that does not accept keywords - no longer passes an empty hash, unless the empty hash is necessary for - a required parameter, in which case a warning will be emitted. Remove - the double splat to continue passing a positional hash. [Feature #14183] - - h = {}; def foo(*a) a end; foo(**h) # [] - h = {}; def foo(a) a end; foo(**h) # {} and warning - h = {}; def foo(*a) a end; foo(h) # [{}] - h = {}; def foo(a) a end; foo(h) # {} - -* Above warnings can be suppressed also with {-W:no-deprecated option}[#label-Warning+option]. - -==== Numbered parameters - -* Numbered parameters as default block parameters are introduced. - [Feature #4475] - - [1, 2, 10].map { _1.to_s(16) } #=> ["1", "2", "a"] - [[1, 2], [3, 4]].map { _1 + _2 } #=> [3, 7] - - You can still define a local variable named +_1+ and so on, - and that is honored when present, but renders a warning. - - _1 = 0 #=> warning: `_1' is reserved for numbered parameter; consider another name - [1].each { p _1 } # prints 0 instead of 1 - -==== proc/lambda without block is deprecated - -* Proc.new and Kernel#proc with no block in a method called with a block will - now display a warning. - - def foo - proc - end - foo { puts "Hello" } #=> warning: Capturing the given block using Kernel#proc is deprecated; use `&block` instead - - This warning can be suppressed with {-W:no-deprecated option}[#label-Warning+option]. - -* Kernel#lambda with no block in a method called with a block raises an exception. - - def bar - lambda - end - bar { puts "Hello" } #=> tried to create Proc object without a block (ArgumentError) - -==== Other miscellaneous changes - -* A beginless range is experimentally introduced. It might be useful - in +case+, new call-sequence of the <code>Comparable#clamp</code>, - constants and DSLs. [Feature #14799] - - ary[..3] # identical to ary[0..3] - - case RUBY_VERSION - when ..."2.4" then puts "EOL" - # ... - end - - age.clamp(..100) - - where(sales: ..100) - -* Setting <code>$;</code> to a non-nil value will now display a warning. [Feature #14240] - This includes the usage in String#split. - This warning can be suppressed with {-W:no-deprecated option}[#label-Warning+option]. - -* Setting <code>$,</code> to a non-nil value will now display a warning. [Feature #14240] - This include the usage in Array#join. - This warning can be suppressed with {-W:no-deprecated option}[#label-Warning+option]. - -* Quoted here-document identifiers must end within the same line. - - <<"EOS - " # This had been warned since 2.4; Now it raises a SyntaxError - EOS - -* The flip-flop syntax deprecation is reverted. [Feature #5400] - -* Comment lines can be placed between fluent dot now. - - foo - # .bar - .baz # => foo.baz - -* Calling a private method with a literal +self+ as the receiver - is now allowed. [Feature #11297] [Feature #16123] - -* Modifier rescue now operates the same for multiple assignment as single - assignment. [Bug #8279] - - a, b = raise rescue [1, 2] - # Previously parsed as: (a, b = raise) rescue [1, 2] - # Now parsed as: a, b = (raise rescue [1, 2]) - -* +yield+ in singleton class syntax will now display a warning. This behavior - will soon be deprecated. [Feature #15575]. - - def foo - class << Object.new - yield #=> warning: `yield' in class syntax will not be supported from Ruby 3.0. [Feature #15575] - end - end - foo { p :ok } - - This warning can be suppressed with {-W:no-deprecated option}[#label-Warning+option]. - -* Argument forwarding by <code>(...)</code> is introduced. [Feature #16253] - - def foo(...) - bar(...) - end - - All arguments to +foo+ are forwarded to +bar+, including keyword and - block arguments. - Note that the parentheses are mandatory. <code>bar ...</code> is parsed - as an endless range. - -* Access and setting of <code>$SAFE</code> will now always display a warning. - <code>$SAFE</code> will become a normal global variable in Ruby 3.0. - [Feature #16131] - -* <code>Object#{taint,untaint,trust,untrust}</code> and related functions in the C-API - no longer have an effect (all objects are always considered untainted), and will now - display a warning in verbose mode. This warning will be disabled even in non-verbose mode in - Ruby 3.0, and the methods and C functions will be removed in Ruby 3.2. [Feature #16131] - -* Refinements take place at Object#method and Module#instance_method. [Feature #15373] - === Command line options -==== Warning option - -The +-W+ option has been extended with a following +:+, to manage categorized -warnings. [Feature #16345] [Feature #16420] - -* To suppress deprecation warnings: - - $ ruby -e '$; = ""' - -e:1: warning: `$;' is deprecated - - $ ruby -W:no-deprecated -e '$; = //' - -* It work (... truncated) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/