Ruby is Object Oriented
Get insight into object-oriented programming in Ruby.
We'll cover the following
Object-oriented programming
Like many other popular languages, Ruby is an object-oriented programming language. Other object-oriented languages that you might have heard of are C++, Java, Python, PHP, and JavaScript. At some point in the 1990s, this paradigm became increasingly popular and is now one of the most prevalent.
Why use the object-oriented approach?
One potential advantage of object-oriented programming is that it tends to fit the way Western cultures perceive and think about the world. Many consider Plato’s Theory of Forms to be the basis of Western philosophy. It argues that concrete things are just imitations, or single instances, of larger, abstract ideas (or forms). For example, there’s the idea of a “human being,” which encompasses everything that humans can be and are. Then there are actual individual human beings like you and me—no two are exactly the same, but they are all represented by the defining idea of a “human being.”
Object-oriented programming languages allow us to describe things in this way. In object-oriented programming languages, the ideas, are called classes. Actual things are called objects.
As a programmer, you can define classes, such as User
and Tweet
, and then create actual instances of them. This could be a real user with a name, email address, password, and picture. You can also define users with the ability to remember their own name and tell it to others when asked…
Every object-oriented programming language includes some classes by default, and so does Ruby. For example, Ruby has classes for numbers, strings (text), and other useful things. As a result, you can perform numerical calculations or text transformations without too much effort.
In fact, you’ll do just that in our first exercises. Later on, you’ll learn to define your own ideas as classes and use them to create actual instances or objects. You’ll then learn how to make them interact with each other and do interesting stuff.
This will make more sense once you start to write your own classes.
Note: There’s some debate about the paradigm of object-oriented programming and whether we should move on to another approach known as functional programming. Some functional languages are Haskell, Go, and Clojure, and they’ve recently started to gain some traction. That being said, Ruby is a good first language to learn, so don’t worry too much about these other languages right now.