Requesting Additions to "What You'll be Building" Message


I would like to suggest that more information be added to the "What You'll be Building" message because there is a lot more going than is stated.

  1. The method "alphabet" is being access from inside the puts statement.
  2. The processed object from the alphabet method is accessed by the puts statement without using a return.

A minor issue is that the code to determine which statements (if/else) would be much cleaner if the method was:
def alphabet (books, rev) and inside the puts they are called with the second argument of true or false. Clean, easy to understand code, is a virtue. Code that uses a twist is seldom necessary and should be avoided.

def alphabetize(arr, rev=false)
  if rev
    arr.sort { |item1, item2| item2 <=> item1 }
    arr.sort { |item1, item2| item1 <=> item2 }

books = ["Heart of Darkness", "Code Complete", "The Lorax", "The Prophet", "Absalom, Absalom!"]

puts "A-Z: #{alphabetize(books)}"
puts "Z-A: #{alphabetize(books, true)}"


value interpolation is covered before this exercise or the author wouldn't be using it. We know that it can take any value or expression (something that yields a value).

If I'm not mistaken, implicit return is covered already, as well. (I could be wrong, haven't been able to find where.)

Both of these features help to make the code more declarative and less procedural.

There is one consideration that would eliminate the need for any kind of return. arr is a reference to books which is a reference object. That means even by a local name, it is still the actual object being accessed. Return is not needed since the object takes the new changes. arr is not a copy of books, but a reference to it.