Skip to content

Instantly share code, notes, and snippets.

@NanoDano
Created June 3, 2020 20:37
Show Gist options
  • Save NanoDano/9b38417b94b35f3a24b5d310c45d6ac0 to your computer and use it in GitHub Desktop.
Save NanoDano/9b38417b94b35f3a24b5d310c45d6ac0 to your computer and use it in GitHub Desktop.
Crystal language basics

Crystal

https://crystal-lang.org is just like Ruby, but it compiles and has threads.

Install

Download the .tar.gz from https://github.com/crystal-lang/crystal/releases/ Extract and add bin/ to PATH. Adds crystal and shards to PATH.

Run playground

crystal play

Compile or run files

crystal build hello.cr
crystal build hello.cr --static

crystal run hello.cr

Standard library documentation

https://crystal-lang.org/api

Initializing a library or app

crstyal init lib mylib
crystal init app myproject

To package and share a module, push to github with the shard.yml file.

To add a package as a dependency in your projects shard.yml:

dependencies:
myproject:
    github: your-github-user/myproject
Run shards install

To require a dependency in the code:

require "myproject"

Documentation

Write docstrings with Markdown formatting to generate docs using:

crystal docs

Hello world

Example hello.cr file:

# hello.cr
puts "Hello!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment