Understanding Accessors in Ruby

One thing that puzzled me as a newbie (disclaimer: I still am) are accessors in Ruby, more commonly known as setters and getters or explicitly described as attr_reader, attr_writer and attr_accessor. Now let’s dive into the code first and describe the concepts of accessors after we’re done with coding. Initializing a Class Let’s say we want to create a class to resemble a Person with a name, and finally let’s try to access that name outside the class:...

February 25, 2018 · 5 min · Franccesco Orozco