[ruby-core:94714] [Ruby master Bug#11068] unable to ommit an optional keyarg if the previous arg is an optional hash
From:
merch-redmine@...
Date:
2019-09-02 04:24:08 UTC
List:
ruby-core #94714
Issue #11068 has been updated by jeremyevans0 (Jeremy Evans).
Status changed from Open to Closed
With the acceptance of #14183, this code now emits warnings as the behavior will change in Ruby 3:
```ruby
foo({b: 1})
# (irb):53: warning: The last argument is used as the keyword parameter
# (irb):51: warning: for `foo' defined here
# ArgumentError (unknown keyword: :b)
```
In Ruby 3, you will not get a warning, and the code will work as expected. To get the Ruby 3 behavior currently, you can do:
```ruby
foo({b: 1}, **(;{}))
# => [{:b=>1}, nil]
```
----------------------------------------
Bug #11068: unable to ommit an optional keyarg if the previous arg is an optional hash
https://bugs.ruby-lang.org/issues/11068#change-81324
* Author: bughit (bug hit)
* Status: Closed
* Priority: Normal
* Assignee:
* Target version:
* ruby -v: ruby 2.2.2p95 (2015-04-13 revision 50295) [x86_64-linux]
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN
----------------------------------------
```
irb(main):001:0> def foo(hash = {}, a: nil); [hash, a] end
=> :foo
irb(main):002:0> foo({b: 1}, a: 1)
=> [{:b=>1}, 1]
irb(main):003:0> foo({b: 1})
ArgumentError: unknown keyword: b
from (irb):1:in `foo'
from (irb):3
from /home/alex/.rbenv/versions/2.2.2/bin/irb:11:in `<main>'
irb(main):004:0>
```
--
https://bugs.ruby-lang.org/
Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>