James Edward Gray II <james / grayproductions.net> writes: >On Dec 9, 2005, at 4:57 AM, Ross Bamford wrote: >> 2) I like documentation. So far, Rdoc is great, but I wonder about >> the following case: >> >> class SomeClass >> attr_accessor :someattr >> >> # But I need to validate, for example, so ... >> def someattr=(i) >> @someattr unless i < 10 >> end >> end Don't use attr_accessor, then. attr_accessor doesn't do any magic; it's just a shorthand that defines default accessor methods. This line: attr_accessor :foo has identical results to this code: def foo @foo end def foo=(new_foo) @foo = new_foo end So if you're going to define your own foo and foo=, just leave out the attr_accessor line. If you're only making your own foo=, you can use attr_reader to get foo(): attr_reader :foo def foo= ... end The other way around is less common, but still doable: attr_writer :foo def foo ... end