Skip to content

Instantly share code, notes, and snippets.

@Sihui
Last active August 4, 2017 07:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Sihui/cd0da278dfbe29603f612c61f972a35f to your computer and use it in GitHub Desktop.
Save Sihui/cd0da278dfbe29603f612c61f972a35f to your computer and use it in GitHub Desktop.
Design Pattern: Iterator and Movie Collections
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