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 Ruby Foundations Strings Review

Chris Massie
Chris Massie
6,233 Points

So for the Extra Credit for the Strings badge, I don't recall learning the method for removing punctuation.

I browsed google for said method, and ended up finding a nifty code bit to create this method, but not the actual method. Did I miss something in the videos?

2 Answers

Hugo Paz
Hugo Paz
15,622 Points

There isn't a method to remove punctuation. You need to use gsub with a regexp. Try string.reverse.gsub(/[^\w\s\d]/, '')

Chris Massie
Chris Massie
6,233 Points

That works. Just was not expecting the Extra Credit to involve foreign code(foreign to me, at least). I'll know to consider all options for next time. Thanks!

Nicholas Olsen
seal-mask
.a{fill-rule:evenodd;}techdegree
Nicholas Olsen
Front End Web Development Techdegree Student 19,342 Points

Maybe my solution was a bit more hackey, but I don't know regular expressions so I used the tr() method like this:

string.tr('`~!@#$%^&*()-=_+[]{}|\:";\'<>?,./', '')