published: 4th of August 2021
Structs have a similiar syntax to a Class and are used to hold data.
# Define an Struct.
struct Stuff
@stuff : String
property stuff
def initialize(@stuff)
end
def print
puts(@stuff)
end
end
# Instatiate the Stuff struct.
s = Stuff.new("my stuff")
# Use the print method.
s.print # => my stuff
https://pragprog.com/titles/crystal/programming-crystal/
https://crystal-lang.org/reference/syntax_and_semantics/structs.html