Kenneth Y. answered 09/25/19
Ruby On Rails/React Developer
Normally when making a class, you create a property and create methods to get and set that property.
attr_accessor helps you by creating those methods for you.
Here is an example without attr_accessor:
Something like this:
That is an example of a simple Dog class that has a property breed. You have a method that gets the breed property, and a setter method that changes the breed property.
Instead of having to type that out yourself, if you used attr_accessor, you could have just done:
And the result would be exactly the same because attr_accessor created those getter and setter methods for the property breed.
Hope that helps :)