Skip to content

[DOC] Tweaks for String.new #13027

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

BurdetteLamar
Copy link
Member

No description provided.

@BurdetteLamar BurdetteLamar added the Documentation Improvements to documentation. label Apr 1, 2025
Comment on lines 14 to 19
s0 = 'foo'.encode(Encoding::UTF_16)
s1 = String.new(s0)
s1.encoding # => #<Encoding:UTF-16 (dummy)>
s0 = ''.encode(Encoding::UTF_16)
s1 = String.new(s0)
s1.encoding # => #<Encoding:UTF-16 (dummy)>
Copy link
Member

Choose a reason for hiding this comment

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

These two examples seems to be showing the exact same thing? What's the second example showing?

the +encoding+ may be an Encoding object, an encoding name,
or an encoding name alias:

String.new(encoding: Encoding::US_ASCII).encoding # => #<Encoding:US-ASCII>
String.new('', encoding: Encoding::US_ASCII).encoding # => #<Encoding:US-ASCII>
Copy link
Member

Choose a reason for hiding this comment

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

What's the purpose of this example? It doesn't seem to be showing anything new.

Copy link
Member Author

Choose a reason for hiding this comment

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

I was trying to show that the default empty string is different from as passed empty string. I have removed the example and changed the call-seq.

Copy link
Member

Choose a reason for hiding this comment

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

How is the default empty string is different from a passed in empty string? It works the same when you specify an encoding.

the +encoding+ may be an Encoding object, an encoding name,
or an encoding name alias:

String.new(encoding: Encoding::US_ASCII).encoding # => #<Encoding:US-ASCII>
String.new('', encoding: Encoding::US_ASCII).encoding # => #<Encoding:US-ASCII>
Copy link
Member

Choose a reason for hiding this comment

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

How is the default empty string is different from a passed in empty string? It works the same when you specify an encoding.

string.c Outdated
/*
*
* call-seq:
* String.new(string = '', **opts) -> new_string
* String.new(string = ''.encode(Encoding::ASCII_8BIT)) , **options) -> new_string
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* String.new(string = ''.encode(Encoding::ASCII_8BIT)) , **options) -> new_string
* String.new(string = ''.encode(Encoding::ASCII_8BIT) , **options) -> new_string

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed.

@BurdetteLamar
Copy link
Member Author

How is the default empty string is different from a passed in empty string? It works the same when you specify an encoding.

But when option encoding is not given, the default empty string is ASCII_8BIT while the passed empty string is UTF_8. That's the distinction I was trying to make.

@BurdetteLamar
Copy link
Member Author

@peterzhu2118, are there still open issues here?

@BurdetteLamar
Copy link
Member Author

@peterzhu2118, will you be reviewing this?

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

Successfully merging this pull request may close these issues.

2 participants