Hexren | 9 Apr 21:29

Documentation of attr_reader a slight criticism

Hi guys,

while the code posted below actually modifies the instance variable. 
There should imho be some kind of info in the Doc for attr_reader.
Right now the doc reads:

"
attr(symbol, writable=false) => nil

Defines a named attribute for this module, where the name is 
symbol.id2name, creating an instance variable (@name) and a 
corresponding access method to read it. If the optional writable 
argument is true, also creates a method called name= to set the attribute.
"

I would think that I am not the only one, new to the language drawing 
the wrong conclusion that setting writable to false actually makes the 
instance variable not writable.

Or am I of the field here ?

Regards
Oliver

class AttrReaderErr
   attr_reader :entries
   def initialize()
     @entries = [0,1,2]
   end

end

showcase = AttrReaderErr.new

puts showcase.entries
#should this really work ?
showcase.entries[1]="foo"
puts "\n"
#it does, but looks wrong to me
puts showcase.entries


Gmane