RbRuby · Lesson 7 of 11
Classes & OOP
Ruby's OOP is clean and expressive. Everything is an object, inheritance is single (by class), and modules fill in for multiple inheritance. The `attr_accessor` macro writes getters and setters so you don't have to.
✦ Tip
Use `attr_accessor` for simple data attributes — it generates clean getter/setter methods. Add custom getter/setter methods only when you need validation or computation. Ruby convention: `def name` for getter, `def name=(val)` for setter.
Use `attr_accessor` for simple data attributes — it generates clean getter/setter methods. Add custom getter/setter methods only when you need validation or computation. Ruby convention: `def name` for getter, `def name=(val)` for setter.