Created
January 8, 2017 17:45
-
-
Save bararchy/ef2c48e5374c6f18306d6b578056e10d to your computer and use it in GitHub Desktop.
Crystal type examples
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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