Join Kevin Skoglund for an in-depth discussion in this video Class reader/writer methods, part of Ruby Essential Training.
We saw how instance attributes used Reader Writer methods to give access to them…from outside of the instance.…Now in this movie we are going to see how we can use Class Reader/Writer methods…in order to get access to our class attributes from outside of the class.…So I am still inside the classes. rb document we've been working with…throughout this chapter, and in the last movie we tried to call the current…animals method on animal, right?…And we can't do that because we don't have a current animals method.…We have a current animals attribute, right?…A class variable that we set, but we don't have a method to be able to read it.…
Well writing that method is trivial, right?…We know how to do that, self.current animals.…And then what should it return?…It should return current animals.…That's all there is to being able to create a Reader method for this that will…let us return that value.…In fact we had already done that here with all species.…We could just simply shorten this to species and then it kind of fits more with…
- 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
Q: You mention e-texteditor.com as a place to get a Windows "sister" version of TextMate. However, e-texteditor.com looks like a Chinese auto website. Are there any other alternatives?
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.