Join Kevin Skoglund for an in-depth discussion in this video Class methods, part of Ruby Essential Training: 2 Classes and Modules.
- [Instructor] In this chapter, we're going to learn…about class, attributes and methods.…That's different from what we learned…about in the last chapter…where we learned to define a class but the attributes…and methods we put inside of it were instance attributes…and instance methods.…These are going to be a little bit different.…Let me explain.…A class method is going to be behaviors that are related…to a class generally, not to a single, specific instance.…And we're going to call them directly on the class,…not on an instance.…In fact, we don't even have to have an instance.…We've already been working with an example of a class method…whenever we call the method New.…
We don't have an instance yet.…We're telling the class to call it New Method.…That's a class method.…What it does is that it returns back an instance to us.…But there is no instance when we call the method.…Another example might be, if we wanted to ask…an invoice class to go find a particular invoice for us.…Maybe it's going to go look in the database…
- 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.