Last active
August 4, 2017 07:29
-
-
Save Sihui/cd0da278dfbe29603f612c61f972a35f 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
class MovieCollection | |
attr_reader :netflix_movies, :amazon_movies | |
def initialize(netflix_movies, amazon_movies) | |
@netflix_movies = netflix_movies | |
@amazon_movies = amazon_movies | |
@all_movies = get_all_movies | |
end | |
private | |
def get_all_movies | |
movies = [] | |
netflix_movies.each do |movie| | |
movies << movie | |
end | |
amazon_movies.each do |movie_id, movie| | |
movies << movie | |
end | |
movies | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment