This repository will be used as the guide during the lecture on fundamentals of handling data using Object Inheritance in Ruby.
This project was built with the following tools:
The following are the concepts covered in this practice session
- Showing how Object Inheritance occurs in ruby
Documentation on the Ruby language can be found here: Ruby Docs
In order to use this repo you need to have the following installed:
- OS [either: Windows 10+, Linux or MacOS(running on x86 or arm architecture)]
- Ruby - 3.1.+
To use this repo on your machine requires some simple steps
-
Open a terminal / command line interface on your computer
-
Clone the repo by using the following:
git clone https://github.com/prince475/phase-3-lecture-videos-inheritance
-
Be patient as it creates a copy on your local machine for you.
-
Change directory to the repo folder:
cd phase-3-lecture-videos-inheritance
-
(Optional) Open it in
Visual Studio Code
code .
-
(Alternate Option) Open it in any editor of your choice.
-
Hurray! You are one step closer to being as intelligent as Einstein.
-
On the top right corner of this page there is a button labelled
Fork
. -
Click on that button to fork the repo to your own account.
-
Take on the process in
Alternative One
above. -
Remember to replace your username when cloning.
git clone https://github.com/your-username-here/phase-3-lecture-videos-inheritance.git
Running the application is very straight forward. You can use the following steps to run the app.
-
Install required dependencies using bundle
bundle install
-
Run the application on the terminal
ruby config/environment.rb
- Require pry just allows us to get into the pry environment and test our code
require 'pry'
- This will be our superclass that all our other classes will inherit from.
- It initializes name and age and they are all accessible through the accessor macro
class Animals
attr_accessor :name, :age
def initialize(name, age)
@name = name
@age = age
end
end
- The child class cat inherting from Animal.
- A less than sign is used to show that Animal is the super class being inherited from.
class Cat < Animal
def speak
'meawww'
end
end
- The second child Dog of the class Animals and many other children can be created solong as a relation is shown.
class Dog < Animal
def speak
'woof'
end
end
- Calling our methods to check if our code runs well
- Close with binding.pry
cat = Cat.new('rose', 10)
cat = Dog.new('bubles', 5)
binding.pru
- Run your ruby file.
This project was contributed to by:
The project is licensed under Apache 2.0.