Join Kevin Skoglund for an in-depth discussion in this video Initialize method, part of Ruby Essential Training: 2 Classes and Modules.
- [Instructor] In this movie, I want us to learn…about the Initialize Method and see how…it can help you to create objects with…sensible defaults or with customizations.…The Initialize Method is a method in Ruby…that's called automatically whenever a new instance…of a class is created.…So, for example, if you call ShoppingCart.new…then Ruby will automatically call a method named Initialize.…It's useful for being able to set attributes…to either default state or to a specific state.…And we set it to a specific state by providing arguments.…
You provide arguments to the new method…and they get passed on to the Initialized Method.…So, for example, if we have a class called Animal…as an attribute accessor for noise…and we then define a method called Initialize.…Whenever we create a new instance of the Animal class,…Initialize will automatically get called.…Inside the Initialize Method I have here,…you can see I'm setting the noise to a default value,…which is just 'Oink!', and then I'm outputting some text.…That's just so I can see that this is actually…
- 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.