- Define a class with a custom initialize routine.
- Set instance variable attributes from initialize.
- Include a default argument for an initialize argument.
You're going to be building a Person
class that accepts a person's name when a
person is initialized. You're also going to be building a Dog
class that
accepts a dog's name and breed on initialization. If no value for the dog's
breed is provided, it should default to "Mutt"
Open this lab with learn open
and run the tests with learn
.
Define a Person
class in lib/person.rb
that provides an #initialize
method
that accepts an argument for the person's name. That argument should be stored
within a @name
instance variable.
Define a Dog
class in lib/dog.rb
that provides an #initialize
method that
accepts an argument for the dog's name. That argument should be stored within a
@name
instance variable.
Additionally, Dog#initialize
should accept a second optional argument for the
dog's breed stored in an instance variable @breed
. When none is provided, it
should default to "Mutt".
Submit your solution with learn submit
.
View Ruby Object Initialize Lab on Learn.co and start learning to code for free.