ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
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:120604] [Ruby master Misc#21025] What's the default encoding of `String.new`?
Date: Fri, 10 Jan 2025 18:13:00 +0000 (UTC)	[thread overview]
Message-ID: <redmine.journal-111432.20250110181259.7174@ruby-lang.org> (raw)
In-Reply-To: <redmine.issue-21025.20250110165715.7174@ruby-lang.org>

Issue #21025 has been updated by deivid (David Rodríguez).


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

----------------------------------------
Misc #21025: What's the default encoding of `String.new`?
https://bugs.ruby-lang.org/issues/21025#change-111432

* 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:

![](Captura%20de%20pantalla%202025-01-10%20a%20las%2017.53.06.png)

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/

  parent reply	other threads:[~2025-01-10 18:13 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-10 16:57 [ruby-core:120602] " deivid via ruby-core
2025-01-10 17:22 ` [ruby-core:120603] " Eregon (Benoit Daloze) via ruby-core
2025-01-10 18:13 ` deivid via ruby-core [this message]
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.journal-111432.20250110181259.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).