From: "Peña, Botp" Date: 2007-09-01T12:42:50+09:00 Subject: Re: attr_reader From: 7stud 7stud [mailto:dolgun@excite.com] # "The corresponding instance variables, @name, @artist, and @duration, # will be created for you." that should read: "The corresponding instance variable getter and setter methods will be created for you." irb(main):092:0> system "qri instance_variables" ---------------------------------------------- Object#instance_variables obj.instance_variables => array ------------------------------------------------------------------------ Returns an array of instance variable names for the receiver. Note that simply defining an accessor does not create the corresponding instance variable. class Fred attr_accessor :a1 def initialize @iv = 3 end end Fred.new.instance_variables #=> ["@iv"] #So, it seems like initialize is what creates the instance variables. not really. irb(main):097:0> class Song2 irb(main):098:1> attr_accessor :x, :y irb(main):099:1> end => nil note, no initialization there irb(main):106:0> ix=Song2.new => # irb(main):107:0> ix.instance_variables => [] irb(main):108:0> ix.x="hi, i am x" => "hi, i am x" note the assignment using the setter method automatically created using attr_accessor irb(main):109:0> ix.x => "hi, i am x" now, we've created an instance var irb(main):110:0> ix.instance_variables => ["@x"] irb(main):111:0> kind regards -botp