refactor: use $LOADED_FEATURES
built-in instead of $"
#605
+1
−1
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_FEATURES
Ruby built-in ... and work around an apparent parsing bug in "universal"ctags
while we're at it (see details below)Thanks @hsbt 🙏
I noticed that quite a few methods defined in
lib/rake/application.rb
were missing from atags
file generated by the latest version of "universal"ctags
.On closer examination, it turns out that all methods defined after the
rake_require
method (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"ctags
and causing it to generate a partial list of tags; using$LOADED_FEATURES
instead of$"
fixes the issue:$LOADED_FEATURES
used 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 additionalrequire
is needed for this change (especially consideringrake
has been targetingruby v2.3
and above).And if nothing else - even putting the
tags
issue aside - this change makes the code more readable and self-explanatory IMO.Finally, by diffing the output of running:
... on the
master
branch as well as this PR's branch, it's easy to see that using$LOADED_FEATURES
indeed results in all Ruby methods getting indexed, even the ones coming after the"problematic"rake_require
method: