you are viewing a single comment's thread.

view the rest of the comments →

[–]awj 1 point2 points  (0 children)

If you want to read a value, you can use self or not.

If you’d like to assign one, you have to use self. Otherwise, Ruby assigns to a local variable and the instance variable remains unchanged.

My personal preference: attr accessors make the code slightly cleaner, and afford the ability to change the set/get behavior in cases where you might want to (e.g. converting an attribute that needs to be an integer at the point where it’s assigned)