From: spinutids@gmail.com
To: ruby-core@ruby-lang.org
Subject: [ruby-core:91574] [Ruby trunk Feature#15606] Precedence of -@ and +@
Date: Sat, 16 Feb 2019 06:02:29 +0000 (UTC) [thread overview]
Message-ID: <redmine.journal-76838.20190216060228.94a530e60f1c6760@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-15606.20190215092417@ruby-lang.org
Issue #15606 has been updated by spinute (Satoru Horie).
Compatibility is essential in Ruby. So, we need strong evidence when we break it.
I do not think the current behavior is weird.
`<something>.abs` returns positive value, consistently.
A programmer who knows `-i.abs` is evaluated as `-(i.abs)` can get an expected result. As a note, `-` in `-1` is not an operator, so `-1.abs == (-1).abs == 1`. `-i.to_s` is also explained in the same way.
I agree that the behavior may be confusing for beginners.
----------------------------------------
Feature #15606: Precedence of -@ and +@
https://bugs.ruby-lang.org/issues/15606#change-76838
* Author: sos4nt (Stefan Schüßler)
* Status: Feedback
* Priority: Normal
* Assignee:
* Target version:
----------------------------------------
`-@` and `+@` seem to have issues with method chaining:
```ruby
i = 5
-i.negative?
# NoMethodError (undefined method `-@' for false:FalseClass)
```
here's another example:
```ruby
# frozen_string_literal: true
+'foo'.upcase!
# FrozenError (can't modify frozen String)
```
I know that I can fix this by adding parentheses, i.e. `(-i).negative?` and `(+'foo').upcase!` but it feels cumbersome.
Shouldn't the above work out of the box?
Unless I'm missing a crucial use case, the precedence for `-@` and `+@` should be changed.
--
https://bugs.ruby-lang.org/
prev parent reply other threads:[~2019-02-16 6:02 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <redmine.issue-15606.20190215092417@ruby-lang.org>
2019-02-15 9:24 ` [ruby-core:91556] [Ruby trunk Feature#15606] Precendence of -@ and +@ mail
2019-02-15 10:23 ` [ruby-core:91559] [Ruby trunk Feature#15606] Precedence " nobu
2019-02-15 10:28 ` [ruby-core:91560] " mail
2019-02-15 10:39 ` [ruby-core:91561] " mail
2019-02-16 6:02 ` spinutids [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-76838.20190216060228.94a530e60f1c6760@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).