简体   繁体   English

Ruby中+ =和= +有什么区别?

[英]What is the difference between += and =+ in Ruby?

I am just learning Ruby and I want to know the difference between 我只是在学习Ruby,我想知道它们之间的区别

a += b

and

a =+ b
  1. a += b is syntactic shorthand for a = a + b a += ba = a + b句法简写
  2. a =+ b is similar to a = + b a =+ b类似于a = + b

So, firstValue = firstValue + secondValue is the same as firstValue = firstValue.+(secondValue) in ruby. 因此, firstValue = firstValue + secondValuefirstValue = firstValue.+(secondValue)相同。 firstValue + = secondValue – increment Add the value of secondValue to the value of firstValue , store the result in firstValue , and return the new value. firstValue + = secondValue -增量的价值添加secondValue到的值firstValue ,结果存储在firstValue ,并返回新值。

  • foo += bar is shorthand for foo = foo + bar . foo += barfoo = foo + bar简写。
  • foo =+ bar is an unusual way to write foo = +bar . foo =+ bar是写foo = +bar一种不寻常的方式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM