Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialNicole Archambault
27,853 PointsWhy no attr_writer for :complete?
I was expecting that we would be creating an attr_writer :complete
for the @complete
instance variable, following up from a previous course example where we did this with @title
. My understanding was that even though it wasn't an attribute being passed in, that it would require this since there is a method created to change the status of @complete
to true
later on.
Is this not the case? If not, is it because we're not passing it in as an argument in initialize
, but rather setting it by default?
Thanks in advance! :)
1 Answer
Taylor Boudreau
7,285 PointsHi there Nicole,
Super late response here, but this question definitely got me thinking about how the attr methods work.
My understanding, in this case as you're never actually writing or reading complete
as it's set within the methods in the class. If you wanted to be a little more free wheeling and let the user set the "completeness" of the item, ("completish", "Partially done", "maybe tomorrow", "totally finished"), then you'd need to add an attr_writer for complete, but you'd lose the consistency gained with a simple boolean.
Hope this helps!
Taylor