{id: other}
{id: sequence-generation}
{id: nil} {i: nil} {i: nil?}
{id: single-quotes-vs-double-quotes}
- Single quotes are for characters
- Double quotes are for strings
{id: no-typechecking}
{id: divide-by-zero-is-infinity} {i: Infinity}
{id: require-other-files}
{id: list-methods}
{id: checking-the-slides}
{id: crystal-mine}
{id: ameba-linter}
shards install
./bin/ameba
{id: gravatar} {i: Digest::MD5.hexdigest}
{id: try}
{id: stderr} {i: STDERR} {i: STDOUT}
- Redirection on the command line using > out and 2> err
{id: return-boolean}
{id: symbols}
{id: docspec}
{id: require}
{aside} require - imports are global. This makes it hard to see in a file where some objects might come from as they might have been required by some other file.
Similarly requiring a bunch of files in a directory is easy to do, but might make it a bit harder for someone without an IDE to find the source of each object. {/aside}
require "./directory/file" # relative path to the cr file
require "./directory/*" # all the cr files in the directory
require "./directory/**" # all the cr files in the directory - recursively
require "some_name" # Find it somewhere (standard library, src directory)
- You can put the
require
statements anywhere but you might want to be consistent in your project. - Make sure you don't have circular requires.
{id: constants}
- Variable names that start with upper-case letter are constants
{id: multiple-assignment}
{id: chained-assignment}
{id: times}
{id: int64-zero}
{id: question-mark} {i: ?}
- meaning "or nil" in type definitions
String?
is the same asString | Nil
- Methods ending with
?
usually return a boolean (true, false) - there is no enforcement of this in Crystal - If a construct might raise an exception adding a question mark can convert that into returning nil
- It is also part of the conditional operator
?:
{id: exclamation-mark} {i: !}
- Methods ending with
!
usually modify the underlying object. - Logical not (before an expression)
{id: ampersand} {i: &}
{id: stdin-dont-accept-nil}
gets
will retunnil
if we press Ctrl-Dgets.not_nil!
will raise an exception
{id: math}
{id: proc} {i: Proc}
{id: enums} {i: enum}
{id: type-of-array-elements}
All the elements of an array "inherit" the type from the array
{id: environment-variables} {i: ENV}
{id: int32-or-nil}
{id: resources}
-
Crystal Programming by Derek Banas from 2018
-
Crystal: Fast as C, Slick as Ruby by Tom Richards from Delegator form 2017
-
Crystal Weekly by Serdar Doğruyol
-
Friends of Crystal by Serdar Doğruyol