Project

General

Profile

Actions

Misc #21025

closed

What's the default encoding of `String.new`?

Added by deivid (David Rodríguez) 6 days ago. Updated 5 days ago.

Status:
Closed
Assignee:
-
[ruby-core:120602]

Description

In the documentation (https://docs.ruby-lang.org/en/3.4/encodings_rdoc.html#label-String+Encoding) I see a good explanation of default string encodings:

However, it does not mention String.new without an argument, which is the one case where I see inconsistent behavior.

irb(main):001> "".encoding
=> #<Encoding:UTF-8>
irb(main):002> String.new("").encoding
=> #<Encoding:UTF-8>
irb(main):003> String.new(a="").encoding
=> #<Encoding:UTF-8>
irb(main):004> String.new.encoding
=> #<Encoding:BINARY (ASCII-8BIT)>

Should this be documented or changed?


Files

Updated by Eregon (Benoit Daloze) 6 days ago

It's just a documentation bug.
It's always BINARY for String.new without args.

Updated by deivid (David Rodríguez) 6 days ago

Cool, thanks for the info, I'll create a PR to improve the documentation.

Actions #4

Updated by deivid (David Rodríguez) 5 days ago

  • Status changed from Open to Closed

Applied in changeset git|cde065c32c8db34eaf2c6b8646a2d4a34e20a3ec.


Clarify documentation for encoding of String.new without arguments

[Bug #21025]

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0