The domain we're going to build out is actors, movies, and roles. Actors can be in many movies and movies can have many actors.
Build out classes for actor
, movie
, and role
. This is a many-to-many-through relationship.Role
is the join class between actor
and movie
.
- a
actor
has manymovie
s throughrole
. - a
movie
has manyactor
s throughrole
. - A
role
belongs to oneactor
- a
role
belongs to onemovie
Actor
- has the following attributes:first_name
- string,last_name
- string,age
- integerActor#first_name
,Actor#last_name
, andActor#age
methods should all return the respective attributesfirst_name
andlast_name
cannot be changed once set, butage
can be updated (since actor's never tell the truth about their age)
Actor.all
- returns an array of all the actor objects that have been createdActor#full_name
- returns a string of a given actor's first and last names concatenated (e.g.,"Tom Cruise"
)Actor#movies
- returns an array of movie object that the actor has acted inActor#credits
- returns a hash where the keys are the movie title and the values are the name of the role the actor played in the movied - e.g.,
> tom_cruise.credits
> # {
> # "Top Gun" => "Maverick",
> # "Mission Impossible" => "Ethan Hung",
> # "The Mummy" => "The guy who kills the mummuy"
> # }
Actor.find_by_full_name(full_name)
- acceptsfull_name
as a string argument and returns a single instance ofactor
that has that name providedActor.no_younger_than(age)
- accepts an integerage
argument and returns an array ofactor
instances whose age is equal to or greater than theage
argument passed in
Movie
- has the following attributes:title
- string,year
- integerMovie#title
andMovie#year
methods should all return the respective attributestitle
anddate
can be changed once set
Movie.all
- returns an array of all the movie objects in the collectionMovie#pretty_print
- returns a string with thetitle
and thedate
concatenated with a colone (:
) character seperating them (e.g.,The Matrix 4: 2021
)Movie#cast
- returns an array ofactor
objects that have a role in the movieMovie#credits
- returns a hash where the keys are the character names of therole
s in the movies and the values are the correspondingactor
full names - e.g.
> batman.credits
> # {
> # "Batman" => "Michael Keaton",
> # "Joker" => "Jack Nicholson"
> # }
Movie.by_year(year)
- accepts an intergeryear
argument and returns an array of movie objects from that year
Role
- has the following attributes:actor
- actor,movie
- movie,character_name
- string representing the name of the characterRole#actor
,Role#movie
, andRole#character_name
methods should all return the respective attributes- all attributes can be updated
Role.all
- returns an array of all the role objects in the collectionRole#movie
- returns themovie
object therole
belongs toRole#actor
- returns theactor
object that played the role