Join Kevin Skoglund for an in-depth discussion in this video Objects, part of Ruby Essential Training.
In the introduction we discussed the fact that Ruby is an object-oriented programming language, and I have pointed out several times that almost everything in Ruby is an object, and that's one of its strengths. Now, in other languages that's not always the case. A lot of languages have something they call primitives, which are like the basic object types that we are about to talk about, but primitives don't have a common relationship to each other. In the case of Ruby, all of these object types that we are going to discuss are all related because all of them are objects. That's the fundamental building block that everything else is built off of.
So keep that in mind in Ruby; everything is an object. Everything you manipulate is an object and everything that's returned by your manipulation is also an object. So what is an object? Well, we call it an object because it's rather analogous to an object that you would have in the real world. So for example, in the real world we would have an object that would be a classroom, that's a thing, and that could be modeled in Ruby as being an object as well. In the real world we would have students that would be in the classroom, and those students would also be modeled as objects, and each of the desk in the classrooms could be an object and so on.
Now, in the real world, a classroom can contain many desks and have many students, who are sitting in a certain order, and we can move students around between the desks, have certain students who are maybe absent on a certain day. All those kind of complex behaviors we can use objects to talk about. It's really analogous to what we are used to in the real world, which makes it nice and easy. But objects can also be abstract. We could have an object for the communication that occurs between students. We could treat their conversation as if it was a physical thing. So it's not always just going to be an actual physical object that we are thinking of when we are modeling things in Ruby.
Now, in programming terms an object is actually an instance of a class. We will talk a lot more about instances and classes in Ruby a little later. But using our example, each unique student would be one example of the more general classification student. In programming we would say that each student is an object or an instance of the class student. They are all unique but they have something in common too. Now that we understand that everything in Ruby is an object, let's take a look at these basic object types that exist in Ruby and begin learning to program with them.
- 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.