Ruby Build an Address Book in Ruby Class Design Contact Class: Part 1

Sean Flanagan
Sean Flanagan
33,219 Points

What does += mean?

I've just reactivated my Team Treehouse status and I've been away from Ruby for a while? Can anyone tell me please what += means? Thanks.

Sean :)

2 Answers

Seth Reece
Seth Reece
32,864 Points

Hi Sean,

+= means to take the value in a variable and add to it. e.g.

a = 1 
a += 1 # a is now 2
b = 10
b += 10 # b is now 20
Sean Flanagan
Sean Flanagan
33,219 Points

Whereas -= takes the value in a variable and subtracts from it?

Thanks Seth. :-)

Sean Flanagan
Sean Flanagan
33,219 Points

It's starting to come back now, gradually. I've upvoted and given Best Answer to your original, very helpful post. Thanks Seth. :)

George Nono
George Nono
11,256 Points

I wrote the code out like this, I feel like it's a lot easier to read :

def full_name if @middle_name.nil? "#{first_name}" + " " + "#{last_name}" else "#{first_name}" + "#{middle_name}" + "#{last_name}" end