Please read for an updated status on RailsCasts:
Learn more or hide this
i was curious about the interpolation of middle_name in the full_name method. why use interpolation there if 'middle_initial' (which i assume is a column in the db) would work too? is it b/c <pre>middle_initial + " " unless middle_initial.nil?</pre> wouldn't work? or would it?
this site is amazing, btw!
Concatonating strings like that will cause an error if middle_initial returns nil, which is why I chose to use string interpolation.
Hi Ryan, I think
name += middle_initial + ". " unless middle_initial.nil?
still work, won't cause any error even if middle_initial returns nil.
B/c the priority should be:
(name += middle_initial + ". ") unless middle_initial.nil?
Please let me know if I'm wrong.
[self.first_name, self.last_name].compact.join(' ')
First sign in through GitHub to post a comment.