Methods, Blocks, & Sorting
Getting Technical

What if we wanted to sort the books by title, but from Z – A, or descending order? It appears that Ruby’s sort method only works for A – Z, or ascending order.

The sort method assumes by default that you want to sort in ascending order, but it accepts a block as an optional argument that allows you, the programmer, to specify how two items should be compared.



Sort your books in descending order on line 8. Use the example of sorting in ascending order on line 4 as a guide.

Display the result in the console.

Folder Icon

Take this course for free

Already have an account?