Last active
August 4, 2017 07:30
-
-
Save Sihui/9ab08ea24b39c5a1c12575e9dbeaf8d3 to your computer and use it in GitHub Desktop.
Design Pattern: Iterator and Movie Collections
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_all_movies | |
movies = [] | |
movie_iterators = [ | |
netflix_movie_iterator, | |
amazon_movie_iterator, | |
hulu_movie_iterator, | |
youtube_movie_iterator, | |
hbo_movie_iterator | |
] | |
movie_iterators.each do |movie_iterator| | |
while movie_iterator.has_next? | |
movies << movie_iterator.next | |
end | |
end | |
movies | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment