W3cubDocs

/Crystal

annotation Flags

Overview

An enum can be marked with @[Flags]. This changes the default values. The first constant's value is 1, and successive constants are multiplied by 2.

@[Flags]
enum IOMode
  Read  # 1
  Write # 2
  Async # 4
end

(IOMode::Write | IOMode::Async).value # => 6
(IOMode::Write | IOMode::Async).to_s  # => "Write | Async"

Defined in:

annotations.cr

© 2012–2020 Manas Technology Solutions.
Licensed under the Apache License, Version 2.0.
https://crystal-lang.org/api/0.35.1/Flags.html