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 Loops Ruby Loops Loop Conditionals

giob
giob
4,006 Points

I understand all of the code from this video with one exception; what does !name.index(/\d/) accomplish? Thanks :)

I know it's checking to ensure there is nothing numerical in the input but I couldn't find this syntax anywhere.

2 Answers

Maciej Czuchnowski
Maciej Czuchnowski
36,441 Points

Did you check the notes under the video which Jason mentions? They contain links that explain the .index method and how regular expressions work. The ! at the beginning is the negation, so if the name contains any numbers, the name.index(/\d/) will return true, the ! will change it to false and so the conditions will not be met.

but, when i tried in the irb, it doesn't return true or false, but it return the index position in the string?

I have done some testing, I got the answer. When you add an exclamation point which is mean negation. If the string contains the certain pattern, it will return the index position but, when you add negation symbol and there is no certain pattern it return nil