From: "J. Cooper" Date: 2008-04-10T04:46:01+09:00 Subject: Re: My error or bug in "attr_reader" ? Well, it's true; the instance variable isn't writable. Doing showcase.entries = [3,2,1,7] will throw an error, because entries is read-only. (There is no entries= method or attr_writer :entries). There is a difference between a read-only attribute that is a collection, and an attribute that is a read-only collection. In the former, you can't up and assign a different collection to the attribute, but you can certainly modify the contents of the collection itself. In the latter, the collection itself (independent of the fact that it's an attribute of a class) isn't modifiable. Here is how to do the latter: class AttrReaderErr attr_reader :entries def initialize() @entries = [0,1,2].freeze # This makes the collection unmodifiable end end showcase = AttrReaderErr.new showcase.entries[1] = "foo" # TypeError: can't modify frozen array showcase.entries = ["foo"] # NoMethodError: undefined method `entries='... -- Posted via http://www.ruby-forum.com/.