Now that ruby structs have keyword_init: true
, and Data class works with keywords out of the box, this is no longer needed. For a more featureful approach, consider portrayal.
Just like regular Struct, but uses keyword arguments.
Person = KwStruct.new(:name, :age)
sammy = Person.new(name: 'Sammy', age: 30)
Any non-existent arguments will raise an ArgumentError.
$ gem install kwstruct
Thanks @apeiros for ideas.
Thanks @bughit for hitting a bug.