Join Kevin Skoglund for an in-depth discussion in this video Class methods, part of Ruby Essential Training.
So far we've been creating instances of our classes, and then we've been calling…methods on that instance.…We can also call methods directly on the class itself, and we call those class methods.…The other ones of course are called instance methods.…So in this movie we're going to look at how we can create our own class methods.…We've already seen how to call a class method, even though we didn't know it,…and that was Animal.new.…New is a class method.…It's a built-in class method to every Ruby object.…So, we can call new, and it returns a new instance to us.…
But it's still a method.…It's a method that exists on the class even when we don't have an instance, and…that's what you are going to use class methods for.…We are going to use a class method when we want the class, to do something for us.…Even though there may not be an instance in sight.…It doesn't matter, maybe there are instances, maybe there aren't.Defining class…methods is very simple.…We do it just the same way we do instance methods except that we put the self…
- 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?
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.