ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
From: "nobu (Nobuyoshi Nakada)" <noreply@ruby-lang.org>
To: ruby-core@ruby-lang.org
Subject: [ruby-core:109825] [Ruby master Bug#17767] `Cloned ENV` inconsistently returns `ENV` or `self`
Date: Fri, 02 Sep 2022 15:01:03 +0000 (UTC)	[thread overview]
Message-ID: <redmine.journal-99064.20220902150102.4551@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-17767.20210331194206.4551@ruby-lang.org

Issue #17767 has been updated by nobu (Nobuyoshi Nakada).


@Dan0042 It is not a "clone".




----------------------------------------
Bug #17767: `Cloned ENV` inconsistently returns `ENV` or `self`
https://bugs.ruby-lang.org/issues/17767#change-99064

* Author: kachick (Kenichi Kamiya)
* Status: Closed
* Priority: Normal
* ruby -v: ruby 3.0.0p0 (2020-12-25 revision 95aff21468) [x86_64-darwin20]
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN, 3.0: UNKNOWN
----------------------------------------
GH-PR: https://github.com/ruby/ruby/pull/4344

Is this an expected behavior? 😅 

```console
$ ruby -v
ruby 3.0.0p0 (2020-12-25 revision 95aff21468) [x86_64-darwin20]
```

```ruby
cloned_env = ENV.clone

p ENV.each_key{}.equal?(ENV) #=> true
p cloned_env.each_key{}.equal?(cloned_env) #=> true

ENV.delete('TEST')

err = ENV.fetch('TEST') rescue $!
p err.receiver.equal?(ENV) #=> true
err = cloned_env.fetch('TEST') rescue $!
p err.receiver.equal?(cloned_env) #=> false

ENV['TEST'] = 'TRUE'
p ENV.select!{ false }.equal?(ENV) #=> true

cloned_env['TEST'] = 'TRUE'
p cloned_env.select!{ false }.equal?(cloned_env) #=> false
```

I guess ruby don't care `Cloned ENV` objects.
Yes, anyone basically do not write these code.
But the behaviors looks weird to me. 😓 

Should block to clone?
Should return ENV?
Should return self?

I think `they return self` makes consistently behaviors and does not break compatibilities.
So I have created this PR 😅 



-- 
https://bugs.ruby-lang.org/

      parent reply	other threads:[~2022-09-02 15:01 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-31 19:42 [ruby-core:103132] [Ruby master Bug#17767] `Cloned ENV` inconsistently returns `ENV` or `self` kachick1
2021-04-02 21:39 ` [ruby-core:103192] " merch-redmine
2021-04-03  5:53 ` [ruby-core:103195] " nobu
2021-05-20  7:52 ` [ruby-core:103908] " nobu
2021-06-07 18:27 ` [ruby-core:104195] " merch-redmine
2022-07-20 16:20 ` [ruby-core:109263] " nobu (Nobuyoshi Nakada)
2022-08-31 17:38 ` [ruby-core:109799] " Dan0042 (Daniel DeLorme)
2022-09-02 15:01 ` nobu (Nobuyoshi Nakada) [this message]

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-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.ruby-lang.org/en/community/mailing-lists/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=redmine.journal-99064.20220902150102.4551@ruby-lang.org \
    --to=ruby-core@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 read-only IMAP folder(s) and NNTP newsgroup(s).