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"