Ruby OOP development – setters, getters, and methods
Ruby utilizes a unique syntax for creating setters and getters in a class. In this guide, we will walk through how to implement these processes.
Creating a class is fairly simple in Ruby. It's so simple that it wasn't even worth dedicating an entire guide to it (I build courses just like I code, I despise wasting my time or yours for dead simple concepts).
To define a class simply type the class
word followed by the name you want to give to your class, and end it with the end
word. Anything contained between class
and end
belongs to this class.
Note
Class names in Ruby have a very specific style requirement. They need to start with a letter and if they represent multiple words, each new word needs also to be an uppercase letter.
We'll start by creating a class called ApiConnector
:
class ApiConnector end
Now classes in Ruby can store both data and methods. But how can we define what data should be included? In many traditional OOP languages such...