[英]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
a += b
is syntactic shorthand for a = a + b
a += b
是a = a + b
句法简写 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 + secondValue
与firstValue = 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 += bar
是foo = foo + bar
简写。 foo =+ bar
is an unusual way to write foo = +bar
. foo =+ bar
是写foo = +bar
一种不寻常的方式。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.