Struct is a collection of attributes with accessor methods,
without having to write the class explicitly.
Struct class generates a new subclass that contains a set of members and their values.
For each member, a reader and writer method is created similar to
> Vehicle = Struct.new(:make, :model) > Vehicle.superclass => Struct > Vehicle.ancestors => [Vehicle, Struct, Enumerable, Object, Kernel, BasicObject]
Struct is bundled with
we can take advantage of methods like
> Vehicle = Struct.new(:make, :model) > Vehicle["Dodge", "Hellcat"] => #<struct Vehicle make="Dodge", model="Hellcat"> > bike = Vehicle.new("Triumph", "Daytona") > bike => #<struct Vehicle make="Triumph", model="Daytona"> > bike.make = "Yamaha" > bike["model"] = "R1" > bike => #<struct Vehicle make="Yamaha", model="R1">
Follow the link for complete article https://www.sandipmane.dev/struct-class-in-ruby