From: ko1@... Date: 2017-01-20T04:41:23+00:00 Subject: [ruby-core:79181] [Ruby trunk Feature#11925] Struct construction with kwargs Issue #11925 has been updated by Koichi Sasada. Another idea is introducing another method to define own struct, such as `T = Struct.define(:a, :b); T.new(a: 1, b: 2)` and so on. (just idea) Moreover we can extend Struct with some properties, like: `Struct.define(:a, b: :read_only)`. These ideas are provided by another person. ---------------------------------------- Feature #11925: Struct construction with kwargs https://bugs.ruby-lang.org/issues/11925#change-62605 * Author: Ilya Vorontsov * Status: Open * Priority: Normal * Assignee: * Target version: ---------------------------------------- Propose to make Struct subclass constructors which accept keyword arguments. Not sure, if it's reasonable to allow `.new` accept kwargs, so may be should use different method named like `.create`: ```ruby Point = Struct.new(:x,:y, :color) pt_1 = Point.create(x: 1, y: 2) # => Point pt_2 = Point.create!(x: 1, y: 2) # => ArgumentError, color not specified. ``` It will greatly simplify work with big structures, especially in cases when struct layout changes and for cases when structure can have lots of non-significant values. It also allows simpler ways to use implement default values for struct members. -- https://bugs.ruby-lang.org/ Unsubscribe: