ere the TagList is defined, I've noticed that #to_s calls the 'tags' accessor.
What the difference would be if '@tags' were called instead?I think Avdi himself explained the advantages to using accessors very well on RubyTapas: Ruby Tapas | #4: Barewords. In summary, accessors are pretty cheap as far as abstractions go, but they give you the freedom to change the implementation of ‘tags’. Maybe the data structure for tags changes, and instead of an array, it now uses a hash internally. If you reference @tags everywhere, you now have multiple places to fix. If you used an accessor, just turn it into a ‘def tags; @tags.keys; end’.
--
You received this message because you are subscribed to the Google Groups "Objects on Rails" group.
To unsubscribe from this group and stop receiving emails from it, send an email to objects-on-rai...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
def to_s
tags.join(", ")
end
def to_ary
@tags
end
I'm guessing, but probably "because humans" ;-)
I'm guessing, but probably "because humans" ;-)