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

Alias for attribute causes aliasing method to appear in Attributes section #1286

Open
gemmaro opened this issue Feb 5, 2025 · 2 comments
Open

Comments

@gemmaro
Copy link
Contributor

gemmaro commented Feb 5, 2025

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.

@flavorjones
Copy link
Collaborator

flavorjones commented Feb 5, 2025

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?

@gemmaro
Copy link
Contributor Author

gemmaro commented Feb 5, 2025

@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">

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants