-
Notifications
You must be signed in to change notification settings - Fork 5.5k
[DOC] Tweaks for String#dump and String#undump #15180
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
base: master
Are you sure you want to change the base?
Conversation
doc/string/dump.rdoc
Outdated
|
|
||
| In the simplest case, the dumped string contains the original string, | ||
| enclosed in double-quotes; | ||
| this example is done in +irb+ (interactive Ruby): |
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 not sure why we need to specify that this example is in IRB?
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.
Changed (enough?).
doc/string/dump.rdoc
Outdated
|
|
||
| Keep in mind that in the second line above: | ||
|
|
||
| - The outer double-quotes are put on by +irb+, |
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.
IRB just outputs the value of the #inspect method.
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.
Changed.
doc/string/dump.rdoc
Outdated
| def dump(s) | ||
| $stdout.write ' String: '; puts s | ||
| $stdout.write ' Dumped: '; puts s.dump | ||
| $stdout.write ' Undumped: '; puts s.dump.undump |
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.
Also, this is the documentation for String#dump, should we even show String#undump? I don't think that's relevant.
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.
You can't (sensibly) undump just anything; it makes sense only for a dumped string. Therefore I've just linked here from undump, so both can be discussed together.
doc/string/dump.rdoc
Outdated
| String: hello | ||
| Dumped: "hello" | ||
| Undumped: hello |
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.
Should we put all the output in a comment? I don't think syntax highlighting will be happy about invalid Ruby syntax.
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 omitted the calls to the helper, and just shown the output. See how you like it.
doc/string/dump.rdoc
Outdated
| In a dump, unprintable characters are replaced by printable ones | ||
| (\String and Undumped are omitted here, because they are all whitespace): | ||
|
|
||
| s = '' | ||
| (7..13).each {|i| s << i } | ||
| # => 7..13 | ||
| dump(s) | ||
| Dumped: "\a\b\t\n\v\f\r" |
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.
In this case, can this example just simply not use the dump method?
doc/string/dump.rdoc
Outdated
| (\String and Undumped are omitted here, because they are all whitespace): | ||
|
|
||
| s = '' | ||
| (7..13).each {|i| s << i } |
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.
It would be useful to list what these values mean like in the previous example.
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.
Good idea. I like what I've added here.
Co-authored-by: Peter Zhu <[email protected]>
|
@peterzhu2118, all comments addressed, I think. |
string.c
Outdated
| * Related: String#dump (inverse of String#undump). | ||
| * undump -> new_string | ||
| * | ||
| * See String#dump. |
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 think we should still have a brief description for undump, we can't just have documentation that links to the inverse.
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.
Added; also touched up in "What's Here."
No description provided.