rdoc icon indicating copy to clipboard operation
rdoc copied to clipboard

Alias for attribute causes aliasing method to appear in Attributes section

Open gemmaro opened this issue 1 year ago • 4 comments

When defining an alias for an attribute in a class, the aliasing method is incorrectly displayed in the attributes section of the generated documentation.

For example, consider the following code in lib/foo.rb:

class Foo
  attr :bar
  alias baz bar
end

When running rdoc, the documentation for the Foo class shows:

Image

This behavior is misleading, as baz is not a separate attribute but an alias method for bar method (and attribute). It would be beneficial to adjust the documentation generation to prevent alias methods from appearing in the attributes section.

gemmaro avatar Feb 05 '25 07:02 gemmaro

Reproduced this behavior on v6.11.0.

@gemmaro Can you help me understand what you expect to see? It sounds like you want to completely omit mentioning the alias, but I think there's value in mentioning it as an alias, perhaps similar to how rdoc renders non-attribute methods:

Image

WDYT?

flavorjones avatar Feb 05 '25 19:02 flavorjones

@flavorjones I agree that having links between aliasing methods and aliased attributes is beneficial. Here's what I expect to see, based on the Darkfish theme (though it may vary in other themes):

  • Aliasing method names should be listed under the instance methods section (e.g., "Public Instance Methods").
  • Each aliasing method should have its own document comment.
  • The description of the aliasing method should include a link to the aliased instance variable, labeled as "Alias for:".
  • The aliased attribute should link back to the aliasing methods, indicated as "Also aliased as:".
  • The left side menu should include the aliasing method under the "Methods" section.

For example, consider the following lib/foo.rb:

class Foo
  # Some document comment about bar.
  attr :bar

  # Some document comment about baz.
  alias baz bar

  # Some document comment about qux.
  def qux; end

  # Some document comment about quux.
  alias quux qux
end

Currently, RDoc generates:

actual Image

What I expect to see is:

expected Image

manually edited diff for op_dir/Foo.html
diff --git a/doc/Foo.html b/doc/Foo.html
index b521e85..c61b374 100644
--- a/doc/Foo.html
+++ b/doc/Foo.html
@@ -72,6 +72,7 @@
   <h3>Methods</h3>
 
   <ul class="link-list" role="directory">
+    <li ><a href="#method-i-baz">#baz</a>
     <li ><a href="#method-i-quux">#quux</a>
     <li ><a href="#method-i-qux">#qux</a>
   </ul>
@@ -107,15 +108,9 @@
         <div class="method-description">
         <p>Some document comment about bar.</p>
         </div>
-      </div>
-      <div id="attribute-i-baz" class="method-detail">
-        <div class="method-heading attribute-method-heading">
-          <span class="method-name">baz</span><span
-            class="attribute-access-type">[R]</span>
-        </div>
 
-        <div class="method-description">
-        <p>Some document comment about bar.</p>
+        <div class="aliases">
+          Also aliased as: <a href="Foo.html#method-i-baz">baz</a>
         </div>
       </div>
     </section>
@@ -126,6 +121,21 @@
          <h3>Public Instance Methods</h3>
        </header>
 
+       <div id="method-i-baz" class="method-detail">
+        <div class="method-heading attribute-method-heading">
+          <span class="method-name">baz</span><span
+            class="method-args">()</span>
+        </div>
+
+        <div class="method-description">
+        <p>Some document comment about baz.</p>
+        </div>
+
+        <div class="aliases">
+          Alias for: <a href="Foo.html#attribute-i-bar">bar</a>
+        </div>
+      </div>
+
       <div id="method-i-quux" class="method-detail method-alias">
         <div class="method-header">
           <div class="method-heading">

gemmaro avatar Feb 05 '25 22:02 gemmaro

Hi. Can I work on this issue?

extern-c avatar Feb 24 '25 23:02 extern-c

@extern-c If you would like to, please do! Feel free to ping me if you want to ask any questions or talk about any ideas.

flavorjones avatar Feb 25 '25 03:02 flavorjones