2014-09-10 40 views
0

所以我可以做到这一点在红宝石? 4 ++是否可以更改Ruby中的“++”运算符?

我最初的使用Google表明我可以重新定义plus,但是当我尝试并定义++时,它会对我造成错误。

test.rb:2: syntax error, unexpected '+', expecting ';' or '\n' 
def ++() 
    ^
test.rb:5: syntax error, unexpected keyword_end, expecting end-of-input 
+2

这也许应该被标记为“重复[在Ruby中没有增量运算符(++)?](http://stackoverflow.com/questions/3717519/no-increment-operator- in-ruby)“和”[为什么Ruby不支持i ++或i-(递增/递减运算符)?](http://stackoverflow.com/questions/3660563/why-doesnt-ruby-support-i-or -i-increment-decrement-operators)“,但这是一个稍微不同的问题,所以我将链接到真正问题的常见答案。 – 2014-09-10 21:25:49

+1

你可以随时请[马茨](http://en.wikipedia.org/wiki/Yukihiro_Matsumoto)支持它,但我怀疑它会发生。此外,“4 ++”应该是什么意思?这在大多数语言中是无稽之谈,因为“4 = 4 + 1”不会奏效。 – tadman 2014-09-10 22:10:38

回答

相关问题