Ruby Build an Address Book in Ruby Class Design Address Class: Part 2

Mark Simcoe
Mark Simcoe
1,046 Points

What 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
MOD
Tim Knight
Treehouse Moderator 28,849 Points

Mark,

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
Mark Simcoe
1,046 Points

Great. Thank you very much for your prompt response.