Content deleted Content added
→Type Inference and Union Types: The provided example was just wrong and generally terrible |
|||
Line 45:
===Type Inference and Union Types===
The following code defines an array containing different types with no usable common ancestor. Crystal automatically creates a union type out of the types of the individual items.
<syntaxhighlight lang="ruby">
desired_things = [:unicorns, "butterflies", 1_000_000]
p typeof(desired_things.first) # typeof returns the compile time type, here (Int32 | String | Symbol)
p desired_things.first.class # the class method returns the runtime type, here Symbol
</syntaxhighlight>
===Concurrency===
|