From: mail@... Date: 2019-02-15T10:39:59+00:00 Subject: [ruby-core:91561] [Ruby trunk Feature#15606] Precedence of -@ and +@ Issue #15606 has been updated by sos4nt (Stefan Sch����ler). nobu (Nobuyoshi Nakada) wrote: > Do you expect `i = -1; -i.abs` to return `+1`? Yes, indeed. I'd expect `.abs` to return a positive value. ```ruby 1.abs #=> 1 -1.abs #=> 1 i = 1 i.abs #=> 1 -i.abs #=> -1 <- not what I'd expect ``` ---------------------------------------- Feature #15606: Precedence of -@ and +@ https://bugs.ruby-lang.org/issues/15606#change-76824 * 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/ Unsubscribe: