Chapter 6. Block Return Values: How Should I Handle This?

You’ve seen only a fraction of the power of blocks. Up until now, the methods have just been handing data off to a block, and expecting the block to handle everything. But a block can also return data to the method. This feature lets the method get directions from the block, allowing it to do more of the work.
In this chapter, we’ll show you some methods that will let you take a big, complicated collection, and use block return values to cut it down to size.
A big collection of words to search through
Word got out on the great work you did on the invoicing program, and your next client has already come in—a movie studio. They release a lot of films each year, and the task of making commercials for all of them is enormous. They want you to write a program that will go through the text of movie reviews, find adjectives that describe a given movie, and generate a collage of those adjectives:
The critics agree, Hindenburg is:
“Romantic”
“Thrilling”
“Explosive”

They’ve given you a sample text file to work off of, and they want you to see if you can make a collage for their new release, Truncated.
Looking at the file, though, you can see your work is cut out for you:
It’s true, this job is a bit complex. But don’t worry: arrays and blocks can ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access