Andrew Walters8,876 Points
Hey guys. In the "Build an address book" course in the Ruby track, we override the to_s method and pass along the format principle def to_s(format = "short") end for example. What does the format do? What kinds of options do we have with it? Thanks!
"short" is a default value for format if you don't specify a value for it. Calling to_s() the value of format would be "short". Calling to_s("long") the value of format will be "long"
Short is the default argument value for the method. Format is just a variable and could be anything. You could put options = "short", or frmt = "short" and it would work the same so long as your case statement inside the method mirrors that variable name (case format, case options, case frmt) Having a default argument like this allows you to call the method without providing any arguments. IE: puts address_book.to_s and still get something in return.
This is how I understand it at this point anyway. :)