Class Attributes and rdoc/Observable

Hi,

two questions or proposals about class attributes:

- If the access methods for a class variable are defined with
  attr_accessor, rdoc shows them as [RW] in the attributes list.

  But when the access method is explicitely defined with def,
  then rdoc does not show it as attribute access, but as an
  instance function.

  Sometimes it would be nice to explicitely write the
  attr= or attr methods (e.g. to do some checks or give default
  values), but to have it listed in the documentation as a
  plain attribute.

  Is there a way to make rdoc recognize methods as attribute
  methods?

  If not, I'd propose a #:attr: flag.

- Is it possible to make attr_writer and attr_accessor notify
  Observers if the value changes? If not, I'd propose to
  define versions that do so.

  If I do understand ruby correctly, then this would mean to
  add new functions like oattr_writer to the Module class.

Hadmut

Hadmut Danisch wrote:

Hi,

two questions or proposals about class attributes:

Do you really mean "class attributes", or "class methods which define
attributes of instances" ? From your questions, it sounds like the latter.

- If the access methods for a class variable are defined with
  attr_accessor, rdoc shows them as [RW] in the attributes list.

  But when the access method is explicitely defined with def,
  then rdoc does not show it as attribute access, but as an
  instance function.

  Sometimes it would be nice to explicitely write the
  attr= or attr methods (e.g. to do some checks or give default
  values), but to have it listed in the documentation as a
  plain attribute.

  Is there a way to make rdoc recognize methods as attribute
  methods?

  If not, I'd propose a #:attr: flag.

There was some discussion of that recently:

http://blade.nagaokaut.ac.jp/cgi-bin/vframe.rb/ruby/ruby-talk/147750?147700-148826

- Is it possible to make attr_writer and attr_accessor notify
  Observers if the value changes? If not, I'd propose to
  define versions that do so.

There's my implementation of that idea at:

http://raa.ruby-lang.org/project/observable/

  If I do understand ruby correctly, then this would mean to
  add new functions like oattr_writer to the Module class.

My version defines an Observable module that you can extend your class with.

Joel VanderWerf wrote:

There was some discussion of that recently:

http://blade.nagaokaut.ac.jp/cgi-bin/vframe.rb/ruby/ruby-talk/147750?147700-148826

Thanks, the solution proposed there seems to work, but I agree with one
of the commenters that it is an odd hack. I'd prefer a solution without
the need to give rdoc additional command line parameters.

I'd prefer a #:attr: flag for class methods which tell rdoc that the
given method is to be listed in the attributes section.

There's my implementation of that idea at:

http://raa.ruby-lang.org/project/observable/

If I do understand ruby correctly, then this would mean to
add new functions like oattr_writer to the Module class.

My version defines an Observable module that you can extend your class with.

Thanks, that's what I was looking for. Will it make its way into the
ruby main distribution?

regards
Hadmut

Hadmut Danisch wrote:
...

There's my implementation of that idea at:

http://raa.ruby-lang.org/project/observable/

If I do understand ruby correctly, then this would mean to
add new functions like oattr_writer to the Module class.

My version defines an Observable module that you can extend your class with.

Thanks, that's what I was looking for. Will it make its way into the
ruby main distribution?

Might be nice, if there are enough users, but the module would have to
be renamed to something like ObservableAttrs first, to avoid conflict
with the standard lib's Observable defined in observer.rb.