-
Notifications
You must be signed in to change notification settings - Fork 5.3k
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
Adding links to literals and Kernel #5192
Conversation
array.c
Outdated
* You can create an \Array object explicitly with: | ||
* | ||
* - Global method {Array}[Kernel.html#method-i-Array]. | ||
* - A {array literal}[doc/syntax/literals_rdoc.html#label-Array+Literals]. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* - A {array literal}[doc/syntax/literals_rdoc.html#label-Array+Literals]. | |
* - An {array literal}[doc/syntax/literals_rdoc.html#label-Array+Literals]. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for working on this. Many of these changes are OK, but I think there should be substantial changes, please see inline comments.
doc/syntax/literals.rdoc
Outdated
If you are writing a large block of text you may use a "here document" or | ||
"heredoc": | ||
If you are writing a large block of text you may use a HereDocument, | ||
sometines written as HereDoc: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This part should be reverted. I've not seen anyone refer to heredocs using such capitalization.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
string.c
Outdated
* | ||
* - Global method {String}[Kernel.html#method-i-String]. | ||
* - A {string literal}[doc/syntax/literals_rdoc.html#label-String+Literals]. | ||
* - A {HereDoc literal}[doc/syntax/literals_rdoc.html#label-Here+Document+Literals]. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
HereDoc
-> heredoc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
array.c
Outdated
* You can create an \Array object explicitly with: | ||
* | ||
* - Global method {Array}[Kernel.html#method-i-Array]. | ||
* - A {array literal}[doc/syntax/literals_rdoc.html#label-Array+Literals]. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The global methods are used for typecasting existing data to the expected type, they are not used for creating new instances (they accept an argument). If you mention the global methods at all, it should be under the section that discusses Many Ruby methods return #{type} objects
. Also, please refer to them as Kernel methods, not global methods, since they aren't truly global (cannot use them in a BasicObject).
For the objects being discussed where you can use #{class}.new
(e.g. Array#new
), it should be listed directly after the literal form, since that is the next most common way of creating a new instance.
FWIW, I prefer the previous documentation even after fixing these issues. I don't think mentioning the to_a
/to_ary
methods (or similar methods for other classes) is important.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW, I prefer the previous documentation even after fixing these issues.
Do you mean this to cover this entire PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, only the parts of the PR where you are adding documentation about global methods and to_a
/to_ary
and similar methods.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done (I think).
hash.c
Outdated
* - Instance method +to_i+, available in some Core and Standard Library classes. | ||
* - Instance method +to_int+, available in fewer classes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* - Instance method +to_i+, available in some Core and Standard Library classes. | |
* - Instance method +to_int+, available in fewer classes. | |
* - Instance method +to_h+, available in some Core and Standard Library classes. | |
* - Instance method +to_hash+, available in fewer classes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, and thanks @esparta. These are horrible errors.
* <code>[]</code>. Arrays can contain different types of objects. For | ||
* You can create an \Array object explicitly with: | ||
* | ||
* - An {array literal}[doc/syntax/literals_rdoc.html#label-Array+Literals]. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RDoc is not only for HTML format, should be rdoc-links.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This style is used in a lot of recent documentation, because people aren't sure how to use an rdoc-link to hyperlink to a specific heading in the generated documentation. Can you show an example of using an rdoc-link to generate the same link? Maybe it is possible with rdoc-label
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Basically, this comes down to these two usages:
* You can create an \Array object explicitly with:
*
* - An {array literal}[doc/syntax/literals_rdoc.html#label-Array+Literals].
*
* You can convert certain objects to Arrays with:
*
* - \Method {Array}[Kernel.html#method-i-Array].
*
I have not found any form for these links that works, other than the above. If someone knows how to write these links without .html
, please provide examples.
Specifically, what's needed is:
- Link to an instance method in
Kernel
. - Link to a section in
doc/syntax/literals.rdoc
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A link to an instance method Kernel would be Kernel#method_name
. So those should be changed. In the example above, switch to:
* - \Method Kernel#Array
Similar changes for other method links.
Linking to section headings can be done with @
, according to the rdoc documentation:
A heading inside the documentation can be linked by following the class or method by an @ then the heading name. RDoc::Markup@Links will link to this section like this: Links at RDoc::Markup. Spaces in headings with multiple words must be escaped with + like RDoc::Markup@Escaping+Text+Markup. Punctuation and other special characters must be escaped like CGI.escape.
That shows how to link to the section heading of a class. However, I'm not sure how to generate a link to a section heading of a file. Maybe {array literal}[doc/syntax/literals.rdoc@Array+Literals]
works?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've tried many things, including these:
{Array}[Kernel#Array]
did not work; generated<a href="Kernel#Array">Array</a>
. which did not work.{array literal}[doc/syntax/literals.rdoc@Array+Literals]
; generated<a href="doc/syntax/literals.rdoc@Array+Literals">array literal</a>
, which also did not work.
Also, various forms with #method-i-Array
did not work.
Could it be that things are different for a module such as Kernel
? And for a file such as literals.rdoc
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, Kernel#Array
does not work. Maybe we need to hear from @nobu on this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm asking @aycabta to fix RDoc.
The links are OK for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, @nobu. When RDoc is fixed, I will sweep the major classes free of these.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Link to a section in
doc/syntax/literals.rdoc
.
I think it would be better to use foo.rdoc#label-bar
for labeled links to foo.rdoc
instead of foo_rdoc.html#label-bar
.
The label-
part is a result of RDoc's internal processing, so it's probably not a good idea either, but if RDoc changes foo.rdoc#bar
to foo_rdoc.html#label-bar
, the part originally written as abc.rdoc#label-def
will now be abc_rdoc.html#label-label-def
. There are many places like this in the existing documentation. Even if other new notations are introduced, careful consideration is needed to ensure appropriate specifications.
Link to an instance method in
Kernel
.
I fixed it by ruby/rdoc#853. You can use Kernel#String
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, @aycabta. If I change to Kernel#String, I won't be able to verify in Ruby 3.0.2. If I put the 8 changes in a PR, can you verify?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm OK with this, but let's see what @nobu has to say regarding the linking format before merging.
@nobu, no one has offered any further improvements to these links. Can this be merged? |
Adds links to the literals doc for classes that have literals. Also adds links to Kernel constructors for classes that have them (e.g., Array, Hash).
I have not yet treated the percent literals, b/c I'm undecided about where in the literals doc they belong: Does
%w
belong in Percent Literals (as now) or in Array Literals (b/c it creates an array)?