How do I check which Operating System (OS) is used in Crystal?

Viewed 168

Is there something similar to Ruby's OS gem which allows me to check if I am running on Mac, Linux or Windows?

1 Answers

This is possible but Crystal is complied, so this can be done at compile time. The internals use flags which seem to be set here.

{% if flag?(:linux) %}
  # Linux
{% elsif flag?(:darwin) %}
  # Mac
{% elsif flag?(:win32) %}
  # Windows
{% end %}
Related