Initialize immutable struct

A more realistic example is a struct that has a method called initialize that can be used to set the attributes of the struct. Each variable with a single @ sign in-front of it is an attribute.

We can initialize some of the attributes by values received from the user and some attributes by generating the value ourselves. e.g. by using a Time object, a Random value or generating or computing it in any other way.

We can print the content of the Struct, but we have no way to access the attributes and no way to change them. Hence this struct is immutable.

struct Person
  def initialize(name : String, email : String)
    @name = name
    @email = email
    @time = Time.utc

foo ="Foo", "")
p! foo
# p!
# Error: undefined method 'name' for Person

foo # => Person(@name="Foo", @email="", @time=2021-07-11 06:22:05.981166766 UTC)