Instance Methods Lab Ruby
Objectives
- Define a class.
- Build instance methods for the class.
Overview
You're going to be adding 2 instance methods to a Dog
and Person
class.
Instructions
Open this lab with learn open
and run your tests with learn
.
Dog
in lib/dog.rb
1. Define Open lib/dog.rb
and add a class definition for a Dog
class.
#bark
in Dog
2. Define Add an instance method #bark
to your Dog
class in lib/dog.rb
that will puts "Woof!"
#sit
in Dog
3. Define Add an instance method #sit
to your Dog
class in lib/dog.rb
that will puts "The Dog is sitting"
.
Person
in lib/person.rb
4. Define a Open lib/person.rb
and add a class definition for a Person
class.
#talk
in Person
5. Define Add an instance method #talk
to your Person
class in lib/person.rb
that will puts "Hello World!"
#walk
in Person
6. Define Add an instance method #walk
to your Person
class in lib/person.rb
that will puts "The Person is walking"
.
When you're done, submit the lab with learn submit
.
View Instance Methods Lab Ruby on Learn.co and start learning to code for free.