Skip to content

Instantly share code, notes, and snippets.

@vanderhoop
Last active August 29, 2015 14:05
Show Gist options
  • Select an option

  • Save vanderhoop/217e7ac2ef16b37fe982 to your computer and use it in GitHub Desktop.

Select an option

Save vanderhoop/217e7ac2ef16b37fe982 to your computer and use it in GitHub Desktop.

Iterating With .each, Part 2:

Unlike methods, blocks can access values outside of their bounds. To drive this point home, follow the directions below, declaring empty arrays outside of blocks and pushing values into these arrays from within blocks.

Directions

  1. If you haven't, pull from upstream master.
  2. Using the data provided in wine.rb, use .each to iterate over the wine_cellar array, pushing all Pinot Noirs into a sensibly-named array.
  3. Save and commit your work.
  4. Now push all wines that with two-word labels into a long_labeled_wines array.
  5. Save and commit your work.
  6. Create two empty arrays, red_wine_cellar and white_wine_cellar, into which you will push the wines into based on their color, i.e. red wines should go into the red_wine_cellar and white wines into the white_wine_cellar.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment