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.
What
This adds the ability to specify verbatim blocks in macros, so macro code isn't immediately execute.
Why
Take a look at how the macro
def_clone
is implemented:Note all the
\{%
and\{{
in there. It's needed because we don't want to execute@type
right away: we want to defer it until the method is executed, so it works like a macro method. The\
is ugly, but it works.With this PR, we can write it like this:
verbatim
basically won't treat the block inside it as macro code, but instead as just a string that's being pasted. Then when theclone
andinitialize_copy
methods are invoked, the pasted code that's actually macro is executed.So this is just a better way to write and do what we can already do.
I also need this for a complete implementation of #6082 . The
JSON::Serialize
module must inject aninitialize
in the included type so that types referenced in attributes (likeconverter
) work well. For example:If
MyConverter
is pasted in the includedJSON::Serialize
module, it will give an error becauseMyConverter
can't be reached from that location (that's the reason why I had to remove all the private types in the specs in that PR). Ifinitalize
is injected with anincluded
macro,MyConverter
can be accessed.But since that injected
initialize
method already uses@type
in macros, I'll have to escape with\
all of that. But it's so much simpler to just surround everything with averbatim
block.