lsegal / yard

YARD is a Ruby Documentation tool. The Y stands for "Yay!"
http://yardoc.org
MIT License
1.95k stars 398 forks source link

Attribute source code #1522

Closed pointlessone closed 2 months ago

pointlessone commented 11 months ago

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:

I have read the Contributing Guide.

lsegal commented 2 months ago

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.