From: Thomas Wieczorek Date: 2008-02-26T18:38:01+09:00 Subject: Re: attr_writer vs attr_accessor On Tue, Feb 26, 2008 at 9:29 AM, ycsunil wrote: > Hello all, > > From readings I understood that attr_accessor is the one which has the > property of attr_reader and attr_writer. If we define a variable as > attr_writer, we can use it to read and write as well. My question is; > why do we need to use attr_accessor since attr_writer does the job of > read and write? > Did you try it? I get an error, when I use the following irb(main):001:0> class Foo irb(main):002:1> attr_writer :bar irb(main):003:1> def initialize irb(main):004:2> @bar = "hallo" irb(main):005:2> end irb(main):006:1> end => nil irb(main):007:0> Foo.new.bar NoMethodError: undefined method `bar' for # from (irb):7 irb(main):008:0> attr_writer just creates the bar=(value) method, no bar() method to access the attribute.