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 trialMark Simcoe
1,046 PointsWhat is the reason for using "!@middle_name.nil?" instead of "@middle_name"?
What is the reason for using "!@middle_name.nil?" instead of "@middle_name"? They both seem to work and @middle_name is shorter.
1 Answer
Tim Knight
28,888 PointsMark,
The big thing I can think of is that if you're checking for @middle_name and @middle_name is defined, but blank/nil it'll still return true because it's defined where of course check if something specifically is not nil would return false because it would be blank.
CORRECTION: Seems like it's really a stylistic choice? Because you're right on... just checking @middle_name will provide you the correct result.
Mark Simcoe
1,046 PointsMark Simcoe
1,046 PointsGreat. Thank you very much for your prompt response.