зеркало из https://github.com/github/ruby.git
Use an even indent in NEWS for code
* Makes it easier to copy-paste and add code backticks.
This commit is contained in:
Родитель
e003f29e21
Коммит
3fea2d91ad
38
NEWS
38
NEWS
|
@ -28,10 +28,10 @@ sufficient information, see the ChangeLog file or Redmine
|
|||
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
|
||||
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
|
||||
|
@ -39,10 +39,10 @@ sufficient information, see the ChangeLog file or Redmine
|
|||
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
|
||||
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
|
||||
|
@ -50,31 +50,31 @@ sufficient information, see the ChangeLog file or Redmine
|
|||
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
|
||||
def foo(h={}, key: 42); end; foo({"key" => 43}, key: 42) # OK
|
||||
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
|
||||
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
|
||||
def foo(opt={}); end; foo( key: 42 ) # OK
|
||||
|
||||
* Non-symbols are allowed as a keyword argument keys if method accepts
|
||||
arbitrary keywords. [Feature #14183]
|
||||
|
||||
def foo(**kw); p kw; end; foo("str" => 1) #=> {"str"=>1}
|
||||
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
|
||||
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
|
||||
|
|
Загрузка…
Ссылка в новой задаче