Hacker News new | ask | show | jobs
by dopamean 4323 days ago
It's worth noting that in Ruby the difference between attr_reader and attr_writer is not the same as read only and write only. You can write to something set with attr_reader. All attr_writer does is allow complete reassignment of that particular instance variable.

This is pretty trivial so bear with me... If you have something that looks like this...

    class Person
      attr_reader :children

      def initialize
        @children = []
      end
    end
You can then do this...

    x = Person.new
    x << "Bobby"
You will have then altered the value of @children without completely reassigning it.