Reader small image

You're reading from  From PHP to Ruby on Rails

Product typeBook
Published inDec 2023
Reading LevelBeginner
PublisherPackt
ISBN-139781804610091
Edition1st Edition
Languages
Right arrow
Author (1)
Bernard Pineda
Bernard Pineda
author image
Bernard Pineda

Bernard Pineda is a seasoned developer with 20 years of web development experience. Proficient in PHP, Ruby, Python, and other backend technologies, he has taught PHP and PHP-based frameworks through video courses on platforms like LinkedIn Learning. His extensive work with Ruby and Ruby on Rails, along with curiosity in frontend development and game development, bring a diverse perspective to this book. Currently working as a Site Reliability Engineer in Silicon Valley, Bernard is always seeking new adventures.
Read more about Bernard Pineda

Right arrow

Inheritance in Ruby

So far, we’ve looked at a few features that come with Ruby’s implementation of the OOP paradigm, but we have neglected to look at one of the core features that help us recycle code. Inheritance can be simplified as the practice of passing the features of a class to create a brand-new child class. With this new class, we can use any of the features from the parent class, create new features, or customize the features that come from the parent class. The syntax for inheritance can be quite different than in PHP, but the behavior is quite similar. With that in mind, let’s take a look at a few use cases and see it in action.

Let’s say we wanted a class that would let us connect to a database. Instead of having to write all the functionality to connect to a database, we could get an already created database class, create a new one that inherited all the database functionality, and then focus on creating just the features that we need. This...

lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
From PHP to Ruby on Rails
Published in: Dec 2023Publisher: PacktISBN-13: 9781804610091

Author (1)

author image
Bernard Pineda

Bernard Pineda is a seasoned developer with 20 years of web development experience. Proficient in PHP, Ruby, Python, and other backend technologies, he has taught PHP and PHP-based frameworks through video courses on platforms like LinkedIn Learning. His extensive work with Ruby and Ruby on Rails, along with curiosity in frontend development and game development, bring a diverse perspective to this book. Currently working as a Site Reliability Engineer in Silicon Valley, Bernard is always seeking new adventures.
Read more about Bernard Pineda