Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attribute source code #1522

Closed
pointlessone opened this issue Dec 19, 2023 · 1 comment
Closed

Attribute source code #1522

pointlessone opened this issue Dec 19, 2023 · 1 comment

Comments

@pointlessone
Copy link
Contributor

Attribute documentation provides fictional code.

Steps to reproduce

Here's how an attribute is defined in the source file.

attr_reader :whatever

Actual Output

In the generated documentation source code for this attribute is this:

def whatever
  @whatever
end

Expected Output

I'd expect the source code to be extracted directly from the source file.

Environment details:

  • OS: macOS Sonoma 14.2
  • Ruby version (ruby -v): 3.0.0p0
  • YARD version (yard -v): 0.9.34

I have read the Contributing Guide.

@lsegal
Copy link
Owner

lsegal commented Aug 26, 2024

This is by design and working as intended, although your expectation may differ. YARD's view source is intended to peek inside implementations, not necessarily act as a source browser. As such, occasionally YARD provides synthetic implementations for certain (well-known) metaprogrammed constructs. In this case, the source code generated by attr_reader is indeed def whatever; @whatever; end. In this case, "source code" is a bit of an overloaded term since there exists two sets of source: that defined by the user, and any source eval'd / generated by the program. YARD tends to favor the latter, as it provides a more accurate view into the actual code / documentation.

There's no real intention to change this behavior unless there's a strong argument against displaying the (also correct) machine generated code. Marking this as closed since it's not in scope for YARD.

@lsegal lsegal closed this as completed Aug 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants