I thought this might be related to the version of Ruby that I'm using, but when I checked the AST returned by ripper with a couple of different Ruby versions, it looks like they're very close to being the same (albeit not identical; see below). Additionally, I actually tried running ripper-tags under both versions and got the same exception both times.
The workaround for now is to rewrite the code, breaking it into distinct calls on separate lines:
class A
attr_reader :x
private :x
end
Somewhat tangentially, older Ruby only likes the rewritten form, because — at least on 2.7.4 — attr_reader returns nil and private complains about being given nil instead of a symbol or string, but it is still syntactically valid, at least insofar as ripper accepts it. In 3.1.4 attr_reader returns [:x] and private is happy with that.
Given a class like this in a project:
Running
ripper-tags -R
will die in the Vim formatter with:The tag object in question is missing the
:name
property:I thought this might be related to the version of Ruby that I'm using, but when I checked the AST returned by
ripper
with a couple of different Ruby versions, it looks like they're very close to being the same (albeit not identical; see below). Additionally, I actually tried runningripper-tags
under both versions and got the same exception both times.Here's Ruby 3.1.2 (ie. with
pp Ripper.sexp('class A; private attr_reader :x; end')
):vs Ruby 2.7.4 (ie. with
pp Ripper.sexp('class A; private attr_reader :x; end')
):The workaround for now is to rewrite the code, breaking it into distinct calls on separate lines:
Somewhat tangentially, older Ruby only likes the rewritten form, because — at least on 2.7.4 —
attr_reader
returnsnil
andprivate
complains about being givennil
instead of a symbol or string, but it is still syntactically valid, at least insofar asripper
accepts it. In 3.1.4attr_reader
returns[:x]
andprivate
is happy with that.