typed attr_* support
#14
Draft
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Adds support for say
attr_accessor :thing => Stringvia AST processingAn open question is on syntax. Currently is supports both hash and keyword hash syntax for the name/type pairs... but this might be confusing for diffenerent cases, eg
attr_readerwhere probably=>syntax is more consistent withfuneg
Also set this up to check types on write of
attr_writerandattr_accessorand on read ofattr_reader... not sure if thats ok and ifattr_accessorshould check on read instead? (as often accessors are 'set' by setting ivars directly?)If we don't care about the specifics of the syntax (keyword vs hash rockets), on the implementation I guess the better thing to do here tho is to just override the
attr_methods rather than using prism? (though just would need to be careful on visibility of wrapper methods if using inline visibility modifiers)Also thinking out loud... since keyword syntax would look like kwargs while
=>would appear as a hash argument I guess you can even differentiate the syntax via just interrogating the argumentsBut still need to consider how to handle visibility... how to define wrapper methods of
attr_that preserves visibility , egif I override
attr_reader(to parse the type signature), then call to the originalattr_readerimplementation the methods generated by it are now public.