Join Kevin Skoglund for an in-depth discussion in this video Override and extend, part of Ruby: Classes and Modules.
- [Instructor] Now that we understand the basics…of class inheritance,…I want to talk more about overriding and extending.…These are the main reasons…that we want to create subclasses.…I mean, obviously, we want to inherit a lot of the behaviors…of the parent class,…but on it's own, that's not enough.…Otherwise, we just have a new class…that acts exactly like the parent.…Overriding and extending is what allows us to modify…those behaviors so they can't be unique to the subclass.…We either override behaviors which we want to perform…differently in the subclass,…or we add new behaviors in the subclass…that the parent doesn't have.…
And that's extending.…Let me give you an example in code.…Let's say that we have a parent class called Sofa.…It has a class attribute called can_open…which is set to false.…And I've got an attribute accessor…for the width and the length.…And I've also got a method called area…which returns the area of the sofa.…The idea being the amount of space…it takes up on a floor plan.…So it's the width times the length…
- Defining a custom class
- Working with instances of a class
- Class and instance attributes and methods
- Class inheritance
- Working with dates and times
- Using modules as namespaces and mixins
- Raising and handling exceptions
Skill Level Beginner
2. Class Attributes and Methods
4. Dates and Times
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.