API Reference
Methods¶
enumerate¶
enumerate(name, values) -> Enumeration
Returns an Enumeration
based on the provided name
and values
table. The values
table can be provided as a list-like table for simple string enums, or as a dictionary-like table for other value types. The method throws an error if a value appears more than once.
List-Like Table Example¶
local Sport = enumerate("Sport", { "Basketball", "Baseball", "Hockey", }) local favoriteSports = { Sport.Basketball, Sport.Baseball, }
Dictionary-Like Table Example¶
local DayOfWeek = enumerate("DayOfWeek", { Sunday = 1, Monday = 2, Tuesday = 3, Wednesday = 4, Thursday = 5, Friday = 6, Saturday = 7, }) local weekendDays = { DayOfWeek.Sunday, DayOfWeek.Saturday, }
Enumeration API¶
fromRawValue¶
fromRawValue() -> EnumerationValue | nil
Returns an EnumerationValue
from the calling Enumeration
or nil if the raw value does not exist
Example¶
local ErrorCode = enumerate("ErrorCode", { NotFound = 404, Forbidden = 403, }) local isErrorCode = ErrorCode.fromRawValue(someResponse.status) ~= nil local isNotFound = responseErrorCode == ErrorCode.NotFound
isEnumValue¶
isEnumValue(value) -> bool
Returns true
only if the provided value is an EnumerationValue
that is a member of the calling Enumeration
Example¶
local ErrorCode = enumerate("ErrorCode", { NotFound = 404, Forbidden = 403, }) local isErrorCode = ErrorCode.isEnumValue(ErrorCode.NotFound)
EnumerationValue API¶
rawValue¶
rawValue() -> string | number | table | function | userdata
Returns the raw underlying value of the EnumerationValue
Example¶
local Color = enumerate("Color", { Black = Color3.fromRGB(0, 0, 0), White = Color3.fromRGB(255, 255, 255), }) local blackColor3 = Color.Black.rawValue()