These are chat archives for dry-rb/chat

9th
Jun 2018
Artem Pyankov
@iBublik
Jun 09 2018 11:16
Hey folks! Question about dry-types. How can I use meta? I.e. I want to use it inside constructor like this - Types::Strict::String.meta(foo: 'bar').constructor { |input| this_type.meta[:foo] }. Is there way to do that?
Gustavo Caso
@GustavoCaso
Jun 09 2018 11:18
I'm not sure from the top of my head, but can you try this
Types::Strict::String.meta(foo: 'bar').constructor { |input| Types::Strict::String.meta[:foo] }
Artem Pyankov
@iBublik
Jun 09 2018 11:22
Nope, that don't work :( For now I don't understand meta use case at all
Gustavo Caso
@GustavoCaso
Jun 09 2018 11:23
To store information about that type, as well for internal use of the library
Here is a good description of how meta is internally
Artem Pyankov
@iBublik
Jun 09 2018 11:29
OK, thanks for the tip. I guess my intensions to use meta for dependency injection are not quiet right.
Nikita Shilnikov
@flash-gordon
Jun 09 2018 11:33
Types::Strict::Integer.meta(multiplier: 2).yield_self { |t| t.constructor { |input| input * t.meta[:multiplier] } }
Gustavo Caso
@GustavoCaso
Jun 09 2018 11:34
As always @flash-gordon to the rescue :smile:
@flash-gordon do you think this a valid use case?
Nikita Shilnikov
@flash-gordon
Jun 09 2018 11:35
time will tell lolol
Gustavo Caso
@GustavoCaso
Jun 09 2018 11:35
lolol