Rumel
Rumel

Reputation: 937

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

Upvotes: 0

Views: 99

Answers (1)

awendt
awendt

Reputation: 13633

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)?

Upvotes: 5

Related Questions