Issue #16111 has been updated by mame (Yusuke Endoh).


> I would like to know why the method to_hash is being called

A method call that accepts keywords checks if the last argument is a Hash or not.  The check includes attempting to convert it by using `to_hash`.  This is the behavior you are seeing.

I agree that it is very strange.  It is elegantly solved if we can separate positional and keyword arguments completely (#14183), but the separation seems to be difficult because the incompatibility is painful.

----------------------------------------
Bug #16111: Combining default positional and keyword arguments is resulting in a `to_hash` method call
https://bugs.ruby-lang.org/issues/16111#change-80848

* Author: mtelford (Michael Telford)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: 2.6.3
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN
----------------------------------------
Combining default positional and keyword arguments is resulting in a `to_hash` method call when I don't believe it should be. It's affecting some code I am writing. The full details of the behaviour I'm describing can be seen in the attached script.

I would like to know why the method `to_hash` is being called (only in certain circumstances) and if this is a bug to be fixed or desired behaviour (and why?).

Thank in advance!

---Files--------------------------------
ruby-bug.rb (1.44 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>