[ruby-core:88855] [Ruby trunk Feature#15076] Struct to raise error when keyword arguments used but not enabled

From: macdevign@...
Date: 2018-09-05 08:29:41 UTC
List: ruby-core #88855
Issue #15076 has been reported by macdevign (Macdevign mac).

----------------------------------------
Feature #15076: Struct to raise error when keyword arguments used but not enabled
https://bugs.ruby-lang.org/issues/15076

* Author: macdevign (Macdevign mac)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
When Struct is used to instantiate object with keyword arguments disabled and yet if instantiated using keyword arguments, the instance fields will be set incorrectly. 

Will it be clearer if a error is raised instead rather than assigning data incorrectly ? This is helpful and save time in nailing such issue in a large code base when there is mixture of Struct define with and without keyword arguments.

For example,

~~~ ruby
Info = Struct.new(:name, :country)  # without keyword argument enabled
c = Info.new(name: "myname", country: "Japan") # Instantiate with keywords
~~~

The c.name contains hash, and c.country is nil




-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:[email protected]?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>

In This Thread

Prev Next