Using instance variables vs attribute accessors

I prefer using attr_reader or wrapping my instance variables in methods for a couple reasons.

  • I like the idea of sending messages rather than directly accessing data, even if it’s internal.
  • If I run into a change, wrapping instance variables allow changes to happen a little more easily.
  • This is not a reason per se, but I also just think using methods instead of instance variables is just a little more aesthetically pleasing.
2 Likes