From: deivid via ruby-core <ruby-core@ml.ruby-lang.org>
To: ruby-core@ml.ruby-lang.org
Cc: deivid <noreply@ruby-lang.org>
Subject: [ruby-core:120602] [Ruby master Misc#21025] What's the default encoding of `String.new`?
Date: Fri, 10 Jan 2025 16:57:15 +0000 (UTC) [thread overview]
Message-ID: <redmine.issue-21025.20250110165715.7174@ruby-lang.org> (raw)
In-Reply-To: <redmine.issue-21025.20250110165715.7174@ruby-lang.org>
Issue #21025 has been reported by deivid (David Rodríguez).
----------------------------------------
Misc #21025: What's the default encoding of `String.new`?
https://bugs.ruby-lang.org/issues/21025
* Author: deivid (David Rodríguez)
* Status: Open
----------------------------------------
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--------------------------------
Captura de pantalla 2025-01-10 a las 17.53.06.png (139 KB)
--
https://bugs.ruby-lang.org/
______________________________________________
ruby-core mailing list -- ruby-core@ml.ruby-lang.org
To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/
next parent reply other threads:[~2025-01-10 16:57 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-10 16:57 deivid via ruby-core [this message]
2025-01-10 17:22 ` [ruby-core:120603] " Eregon (Benoit Daloze) via ruby-core
2025-01-10 18:13 ` [ruby-core:120604] " deivid via ruby-core
2025-01-10 19:48 ` [ruby-core:120605] " deivid via ruby-core
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=redmine.issue-21025.20250110165715.7174@ruby-lang.org \
--to=ruby-core@ml.ruby-lang.org \
--cc=noreply@ruby-lang.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).