Join Kevin Skoglund for an in-depth discussion in this video Subclass overriding, part of Ruby Essential Training.
In the last movie we saw how we could inherit all of the methods and attributes…from a parent superclass into the child subclass.…But what about, when you don't want to take all of the methods?…Let's say you want everything that's in the parent class except there are a…couple of things you want to do differently than the parent did them.…Well, we can do that by overriding methods in the subclass.…So here I am in the same classes.rb file we've been working with throughout the…chapter and I've got class Animal and then I've created a subclass of Cow, which…doesn't have any attributes or methods in it.…
It's inheriting all of its methods and all of its attributes from the Animal class.…Now, let's take a look here at color.…Right now we have a method inside our Animal class called Color.…The color is blank.…Let's try and access that.…Down here we'd already created an instance of the Cow called maisie.…Let's drop down one more line here and let's say puts maisie.color, all right.…So we'll save that.…
- Using Ruby in the Interactive Ruby Shell and in standalone scripts
- Learning to write custom code blocks to find, merge, and sort
- Using modules for namespacing or as mix-ins
- Reading from and writing to files
- Creating a full Ruby project from start to finish
Skill Level Beginner
1. Getting Started with Ruby
2. Ruby Object Types
3. Control Structures
4. Code Blocks
8. Working with Files
9. Ruby Project: Creating the Food Finder
- 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.