Strings

  • Strings in Crystal are are declared with double quotes ("") .
  • Strings are stored as as sequence of UTF-8 encoded characters.
  • Strings are immutable.
crystal
# Define a string.
stuff = "stuff"

# Multi-line string.
stuff_and_things="stuff
and
things"

Symbols

  • Symbols in Crystal are declared by prefixing a colon (:) to a variable.
  • Every instance of a Symbol is the same object. Symbols are stored as a unique Int32 value, which saves memory compared to strings.
  • Symbols are immutable.
  • Symbols are evaluated at runtime.
crystal
# Define a symbol.
stuff = :stuff

# Define a symbol enclosed in double quotes.
# This allows for a space in the symbol.
things = :"my things"

# Symbols are a good options for hash keys.
stuff_and_things = {
  :stuff => "my stuff",
  :things => "my things"
}

Boolean

Numbers

Union Types