[#91458] [Ruby trunk Feature#4475] default variable name for parameter — matz@...
Issue #4475 has been updated by matz (Yukihiro Matsumoto).
3 messages
2019/02/07
[ruby-core:91574] [Ruby trunk Feature#15606] Precedence of -@ and +@
From:
spinutids@...
Date:
2019-02-16 06:02:29 UTC
List:
ruby-core #91574
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テシテ殕er) * 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: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe> <http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>