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 trialOliver Ruby
4,474 PointsAlphabetize an array
I'm working on the build an address book project. After I add a new contact, it pushes the contact to the end of the contacts array. when I print the contact list to the screen, I want to alphabetize the contacts array first. I have tried the contacts.sort method, but it doesn't seem to work. How would I go about doing this?
Any assistance is greatly appreciated
Oliver Ruby
4,474 PointsOliver Ruby
4,474 PointsOnce again thanks Clayton. This was the bit of code that ended up working. Thanks for sending me in the right direction.
@contacts.sort_by!{|contact|contact.last_name}