Skip to content

Instantly share code, notes, and snippets.

@joeldrapper
Created November 29, 2023 14:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joeldrapper/de46f541042ed9f6381397c23e3fcf99 to your computer and use it in GitHub Desktop.
Save joeldrapper/de46f541042ed9f6381397c23e3fcf99 to your computer and use it in GitHub Desktop.
Accordion of Literal types
# 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