syclee
syclee

Reputation: 697

What is the method symbol for += in ruby?

x + y 

is syntactic sugar for

x.send(:+, y)

What is this a syntactic sugar for?

x += y

I've tried

x.send(:+=, y)

but it doesn't work

Upvotes: 6

Views: 699

Answers (1)

Andrey Deineko
Andrey Deineko

Reputation: 52377

It is not a method. It is a short way (syntactic sugar) for writing following:

x = 1
#=> 1
x += 1 # same as x = x + 1
#=> 2

Upvotes: 7

Related Questions