Hash

Yes, but then the tests fail because I need to prepend all calls to head
with @, which muddles the readability of the code.

But the real reason that I like this POODR convention is that I find it
easier to maintain (when I come back to read the code) to have a clear
division between public and private methods, and having all the accessors,
writers and readers declared from the start so we know which are the
instance variables in play going forward. As a bonus, I try to not use the
@ and make it all more english.


On Wed, Oct 29, 2014 at 10:32 PM, Brook Riggio <notifications@github.com>
wrote:

> In lib/linked_list/linked_list.rb:
>
> > +    val
> > +  end
> > +
> > +  def to_s
> > +    val.to_s
> > +  end
> > +
> > +  private
> > +
> > +  attr_writer :val, :nexxt
> > +end
> > +
> > +class LinkedList
> > +  private
> > +
> > +  attr_accessor :head
>
> So, if it's a private instance variable, with no getters or setters, you
> can simply declare it in your initializer, and be done. No attr_* methods
> are needed at all. Just create/access the inst var where and when you need
> it internally.
>
> —
> Reply to this email directly or view it on GitHub
> <https://github.com/sotoseattle/data-structures/pull/7/files#r19588403>.
>