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 trialSean Flanagan
33,235 PointsWhat 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
32,867 PointsHi 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
George Nono
11,256 PointsI 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
Sean Flanagan
33,235 PointsSean Flanagan
33,235 PointsWhereas -= takes the value in a variable and subtracts from it?
Thanks Seth. :-)
Seth Reece
32,867 PointsSeth Reece
32,867 PointsYep.
Sean Flanagan
33,235 PointsSean Flanagan
33,235 PointsIt's starting to come back now, gradually. I've upvoted and given Best Answer to your original, very helpful post. Thanks Seth. :)