A Literal Ruby Gem#
See the website for documentation.
For self-hosted knots, clone URLs may differ based on your setup.
Download tar.gz
This changes the behavior of `to_s` and `to_sym` on Enums.
`to_s` returns a humanized version of the demodularized class name, eg:
"Red," "Slate gray," "Spring green"
`to_sym` converts the demodularized class name to a symbol, eg: `:Red`,
`:SlateGray`, `:SPRING_GREEN`
Note that this was deemed a minor breaking change.
---------
Co-authored-by: Joel Drapper <joel@drapper.me>
Co-authored-by: Alexey Zapparov <alexey@zapparov.com>
Proposal:
It would be nice to have a `define` like the [native Data
structure](https://docs.ruby-lang.org/en/master/Data.html). It is useful
for code like this:
```ruby
# Before
class CreateUser
Success = Class.new(Literal::Data) do
prop :user, User
end
Failure = Class.new(Literal::Data) do
prop :reason, Symbol
prop :user, User
end
end
# After
class CreateUser
Success = Literal::Data.define(user: User)
Failure = Literal::Data.define(reason: Symbol, user: User)
end
```
With this define, we lose the ability to specify kind, reader,
predicate, and default values, but I believe the goal is to provide a
straightforward way to define simple data structures.
Co-authored-by: Joel Drapper <joel@drapper.me>
Proposal:
[Native Data
structure](https://docs.ruby-lang.org/en/master/Data.html#method-c-new)
allows objects to be instantied using `[]`, eg.
```ruby
Measure = Data.define(:amount, :unit)
Measure.new(amount: 1, unit: 'km')
#=> #<data Measure amount=1, unit="km">
Measure[amount: 1, unit: 'km']
#=> #<data Measure amount=1, unit="km">
```
I think Literal::Data should allow this syntax too to have an DX closer
to native Data structure. It was the first way I tried to instance a
Literal::Data and I got an error `undefined method '[]' for class Xyz`.
See the website for documentation.