From: duerst@it.aoyama.ac.jp
To: ruby-core@ruby-lang.org
Subject: [ruby-core:91619] [Ruby trunk Bug#15616] Chained destructive methods fail when using +@ to unfreeze a frozen string
Date: Mon, 25 Feb 2019 06:14:54 +0000 (UTC) [thread overview]
Message-ID: <redmine.journal-76883.20190225061452.4207b6176ea6f524@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-15616.20190222145228@ruby-lang.org
Issue #15616 has been updated by duerst (Martin Dürst).
Status changed from Open to Rejected
Yes. It's a matter of precedence. The "Pickaxe" book describes it as
> Single terms in an expression may be any of the following:
>
> [some cases omitted]
>
> - Method invocation
That means that in ```+foo.gsub!("bar", "car")```, the `.` of method invocation has higher precedence than the `+`, and so you need to use parentheses if you want to change the order of evaluation.
----------------------------------------
Bug #15616: Chained destructive methods fail when using +@ to unfreeze a frozen string
https://bugs.ruby-lang.org/issues/15616#change-76883
* Author: cianooooo (Cian O)
* Status: Rejected
* Priority: Normal
* Assignee:
* Target version:
* ruby -v: 2.6.1
* Backport: 2.4: UNKNOWN, 2.5: UNKNOWN, 2.6: UNKNOWN
----------------------------------------
Using the +@ syntax to unfreeze a string does not work when chaining destructive methods
Consider the following;
``` ruby
foo = "bar".freeze
+foo.gsub!("bar", "car")
```
This raises;
``` ruby
FrozenError: can't modify frozen String
```
However, I would have expected this to work since +@ should return a duplicated mutable string.
--
https://bugs.ruby-lang.org/
prev parent reply other threads:[~2019-02-25 6:15 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <redmine.issue-15616.20190222145228@ruby-lang.org>
2019-02-22 14:52 ` [ruby-core:91609] [Ruby trunk Bug#15616] Chained destructive methods fail when using +@to unfreeze a frozen string cianol
2019-02-22 15:51 ` [ruby-core:91610] " pdahorek
2019-02-25 6:14 ` duerst [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-76883.20190225061452.4207b6176ea6f524@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).