Created
November 29, 2023 14:44
-
-
Save joeldrapper/de46f541042ed9f6381397c23e3fcf99 to your computer and use it in GitHub Desktop.
Accordion of Literal types
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Okay | |
class Foo < Literal::Data | |
attribute :sizes, Array | |
end | |
# Better | |
class Foo < Literal::Data | |
attribute :sizes, Array(Symbol) | |
end | |
# Even better | |
class Foo < Literal::Data | |
attribute :sizes, _Array( | |
_Union(:sm, :md, :lg, :xl) | |
) | |
end | |
# Much better | |
class Foo < Literal::Data | |
Size = _Union(:sm, :md, :lg, :xl) | |
attribute :sizes, _Array(Size) | |
end | |
# Very good | |
class Foo < Literal::Data | |
class Size < Literal::Enum(Symbol) | |
SM(:sm) | |
MD(:md) | |
LG(:lg) | |
XL(:xl) | |
end | |
attribute :sizes, _Array(Size) | |
end | |
# Best | |
class Foo < Literal::Data | |
class Size < Literal::Enum(Symbol) | |
SM(:sm) | |
MD(:md) | |
LG(:lg) | |
XL(:xl) | |
end | |
attribute :sizes, Literal::Array(Size) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment