refactor: use $LOADED_FEATURES built-in instead of $"
#605
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.
tl;dr - replace
$"with the equivalent - but much more descriptive -$LOADED_FEATURESRuby built-in ... and work around an apparent parsing bug in "universal"ctagswhile we're at it (see details below)Thanks @hsbt 🙏
I noticed that quite a few methods defined in
lib/rake/application.rbwere missing from atagsfile generated by the latest version of "universal"ctags.On closer examination, it turns out that all methods defined after the
rake_requiremethod (defined here in the Ruby source file) don't get indexed byctags:After some experimentation - and most likely due to a parsing bug in
ctags- it turns out that Ruby's$"built-in is hmmm "confusing"ctagsand causing it to generate a partial list of tags; using$LOADED_FEATURESinstead of$"fixes the issue:$LOADED_FEATURESused to be an alias for$"defined inEnglish.rb, but inruby 1.9.3(ruby/ruby@6dcbfbc) it was removed as an alias and was implemented as a "proper" built-in, so no additionalrequireis needed for this change (especially consideringrakehas been targetingruby v2.3and above).And if nothing else - even putting the
tagsissue aside - this change makes the code more readable and self-explanatory IMO.Finally, by diffing the output of running:
... on the
masterbranch as well as this PR's branch, it's easy to see that using$LOADED_FEATURESindeed results in all Ruby methods getting indexed, even the ones coming after the"problematic"rake_requiremethod: