Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

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

Sean Flanagan
Sean Flanagan
33,235 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,867 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,235 Points

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

Thanks Seth. :-)

Sean Flanagan
Sean Flanagan
33,235 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