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 trialjuliaatl
3,890 PointsAddress 'short' and 'long' if stmt question - easy probably
In the address class part 1 Jason uses this: <p> <br>def to_s(format = 'short')</br> <br>address = ''</br> <br>case format</br> <br> when 'long'</br> <br>address += street_1 + "\n"</br> <br><em> address += street_2 + "\n" if !street_2.nil?</b></em> <br> address += "#{city}, #{state} #{postal_code}"</br> <br>when 'short'</br> <br> address += "#{kind}: "</br> <br> address += street_1</br> <br> <em> if street_2</br> <br> address += " " + street_2</em></br> <br> end</br> <br> address += ", #{city}, #{state}, #{postal_code}"</br> <br> end</br> <br> address</br> <br>end</br>
<br>end </br>
Question: Why would you use the <b>address += street_2 + "\n" if !street_2.nil?</b> in the long and not in the short (below it... it seems he uses a regular if...end)
Can you use the 'long' version in both?? Is there a reason behind why those 2 formats??
thanks,