使用Ruby 2.3.1,我得到与
相对优先级相关的不直观行为=
rescue
(所谓的modifier-rescue
)raise
这个表达式(1):
x = raise "z" rescue 2 # evaluates to 2, BUT x still has previous value
表现得像(2):
(x = raise "z") rescue 2 # evaluates to 2, BUT x still has previous value
但这些都符合我的预期(3-5):
x = (raise "z" rescue 2) # evaluates to 2, x now equals 2
x = raise("z") rescue 2 # evaluates to 2, x now equals 2
x = (raise "z") rescue 2 # evaluates to 2, x now equals 2
根据this RDoc,modifier-rescue
的优先级高于作业=
。我无法看到任何方式(1)可以为(2)括号而不是(3-5)中的任何一个。这里发生了什么?