简体   繁体   中英

Is it possible to change the “++” operator in Ruby?

So can I make this happen in ruby? 4++

My initial googling showed I can redefine plus but when I try and define ++ it will error on me.

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

You cannot change it because there is no operator ++ in Ruby to begin with. That's why you get a syntax error.

See Why doesn't Ruby support i++ or i— (increment/decrement operators)?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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