From: takashikkbn@... Date: 2017-12-12T08:16:15+00:00 Subject: [ruby-core:84188] [Ruby trunk Feature#11925] Struct construction with kwargs Issue #11925 has been updated by k0kubun (Takashi Kokubun). As Matz approved, I committed only keyword_init option which is equivalent to "Point.create(x: 1, y: 2)" in original suggestion. If you still want "Point.create!" version which raises ArgumentError (keyword_init initializes unspecified fields with nil), please file another ticket. ---------------------------------------- Feature #11925: Struct construction with kwargs https://bugs.ruby-lang.org/issues/11925#change-68301 * Author: prijutme4ty (Ilya Vorontsov) * Status: Closed * 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: