By the end of this, developers should be able to:
#initialize
and .new
.training
, for your work.training
branch.bundle install
.Sometimes a method is associated with a class, not an object.
Observe how a Method on a Class differs from a method on an Instance that Class.
Let's discuss the code below in lib/pet.rb
In the Animal class, and the ::new
method is recieved by the Animal class, with 'Zeno' and 'cat' as an arguments. It then calls the instance method #initialize
with 'Zeno' and 'cat' as an arguments, which assigns 'Zeno' to an instance variable, @name
and 'cat' to the instance variable @species
.
The Pet class is different. The Pet class is used here to give us meta-data about a list of Pets. When we get to Rails, this data will be information we get back from the database.
Where will the method dog_count
be recieved?
What about all
?
search
on Album (in lib/album.rb
) to search the
collection of songs by title
.count
that returns the total number of songs on the album.bin/rake test
to test your workBonus: