'Cece n’est pas une pipe.'

Posted by JGB on July 9, 2018

Ruby is an object-orientated programing language. Everything in Ruby is an object - strings, numbers, etc. While this is an abstract thought, it is fairly simple to grasp. Viewing the objects as “containers” is quite helpful. Rene Magritte’s artwork “Cece n’est pas une pipe.” depicts an image of a tobacco pipe with the words “Cece n’est pas une pipe.” (“This is not a pipe.”) written bellow it. A picture of a pipe is not actually a pipe, rather it is a representation of that object. Similarly, in Ruby, we use data to create objects that represent the real world. You can create objects and give these objects properties and functions. For example, you can create a class called duck and give the duck class properties such as name or color (attributes) and give it functions (i.e. via methods) such as “quack!” From your duck class, you can create a number of duck instances and each of these instances will be a new duck object. As Ruby-ites say “If it looks like a duck and quacks like a duck, it must be a duck…”

Ruby is so powerful because it allows for inheritance, encapsulation, and polymorphism. Inheritance: classes can inherit values from parent classes. Encapsulation: allows you to “hide” information within your code and make that unavailable to the rest of your code (i.e. private v. public info within a method). Polymorphism: use the same method in different ways (this allows for shorter programs). Creating objects (or “containers”) in programming languages allows for simplified and maintainable code. With less code – it is more readable and much easier to debug.