Skip to content

Instantly share code, notes, and snippets.

@bararchy
Created January 8, 2017 17:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bararchy/ef2c48e5374c6f18306d6b578056e10d to your computer and use it in GitHub Desktop.
Save bararchy/ef2c48e5374c6f18306d6b578056e10d to your computer and use it in GitHub Desktop.
Crystal type examples
# This is an array if Int32
a = [] of Int32
# or we can also do this
a = Array(Int32)
# or even
a = [1,2,3]
# this is a Hash
a = {} of Symbol => Int32
# or
a = Hash(Symbol, Int32)
# or
a = {:foo => 1, :bar => 2}
# this is an array of mixed types
a = Array(Int32|String)
# add stuff to the array
a << "foo"
a << 1
print a
# => ["foo", 1]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment