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

Enhanced RDoc for Integer #5118

Merged
merged 2 commits into from Nov 15, 2021
Merged

Enhanced RDoc for Integer #5118

merged 2 commits into from Nov 15, 2021

Conversation

BurdetteLamar
Copy link
Member

Treats:

#allbits?
#anybits?
#nobits?
#succ
#pred
#chr`
#to_s
#+
#-

This is a replacement for the merged-then-reverted PR 5099, which had an offending character in a C-code comment (from an irb example). The containing RDoc is now moved out of numeric.c and into numeric.rb, which I hope will be ok.

@BurdetteLamar BurdetteLamar marked this pull request as draft November 15, 2021 17:21
Copy link
Contributor

@jeremyevans jeremyevans left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did some more research into the chr method, and think the documentation should be fixed for it. It's probably best to fix the documentation, but still include the fixed documentation in the numeric.c file, for consistency. Only methods defined in numeric.rb should be documented there.

numeric.rb Outdated
# 65.chr # => "A"
# 0..chr # => "\x00"
# 255.chr # => "\xFF"
# 255.chr(Encoding::UTF_8) # => "ÿ"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please remove this example line, or change it so it doesn't have the ÿ character? For example:

string = 255.chr(Encoding::UTF_8)
string.encoding # => Encoding::UTF_8

FWIW, on my machine (where Encoding.default_internal is nil):

255.chr(Encoding::UTF_8) # => "\u00FF"

So the example you are using depends on configuration.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

numeric.rb Outdated

# Document-method: Integer#chr
# call-seq:
# chr(encoding = Encoding.default_internal) -> string
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this call-seq is correct in terms of the default argument:

Encoding.default_internal ='UTF-8'
255.chr.encoding # => #<Encoding:ASCII-8BIT>
255.chr(Encoding.default_internal).encoding # => #<Encoding:UTF-8>

Encoding.default_internal = nil
255.chr.encoding # => #<Encoding:ASCII-8BIT>
255.chr(Encoding.default_internal) # TypeError

Probably needs two call-seq lines, one for no argument and one for an argument provided, since the behavior when providing a argument with the given default value is not the same as not providing an argument.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Contributor

@jeremyevans jeremyevans left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@BurdetteLamar BurdetteLamar marked this pull request as ready for review November 15, 2021 19:50
@BurdetteLamar BurdetteLamar merged commit f31b7f0 into ruby:master Nov 15, 2021
@ioquatix
Copy link
Member

TY!

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