Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Empty struct

  • struct

Structs are very powerful constructs in Crystal. Very similar to classes, but they are usually faster.

In the first example we create an empty struct. It does not give as a lot, but we have to start somewhere.

struct MyConfig
end

cfg = MyConfig.new
p! cfg
p! typeof(cfg)
cfg # => MyConfig()
typeof(cfg) # => MyConfig