Issue #15849 has been updated by ko1 (Koichi Sasada).

Status changed from Open to Closed

I believe Jeremy :) and if it is not the same issue, please reopen it.


----------------------------------------
Bug #15849: Using hash as first positional argument, mixed with named arguments causes unexpected behavior
https://bugs.ruby-lang.org/issues/15849#change-80159

* Author: jsmartt (Jared Smartt)
* Status: Closed
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: ruby 2.4.5p335 (2018-10-18 revision 65137) [x86_64-linux]
* Backport: 2.4: UNKNOWN, 2.5: UNKNOWN, 2.6: UNKNOWN
----------------------------------------
If the first argument of a method defaults to an empty hash, and there is another keyword argument after it, it does not set first parameter given to the first argument

For example:

``` ruby
data = {}
# This method does not modify the data hash as expected
def add_to_data(data = {}, key: 'a')
  data[key] = 'value'
end
add_to_data(data)
puts data   # {}
```

Trying the following produces an error:

```ruby
data = { b: 'val' }
add_to_data(data)   # ERROR: unknown keyword: b (ArgumentError)
```

There are a lot of other similar combinations of this method definition that do work as expected. It appears that having a default value for that first positional argument is what causes issues; see the attached script.

---Files--------------------------------
ruby_named_param_bug.rb (1.2 KB)


-- 
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>