Class Attributes and rdoc/Observable

H

Hadmut Danisch

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
 
J

Joel VanderWerf

Hadmut said:
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.
 
H

Hadmut Danisch

Joel said:

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/




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
 
J

Joel VanderWerf

Hadmut Danisch wrote:
...
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

[ANN] RDoc 3 6
rdoc and virtual attributes 2
rdoc/attributes 10
[ANN] rdoc 3.3 Released 0
[ANN] rdoc 2.5 Released 7
Documenting attributes with Rdoc 0
[ANN] rdoc 2.1.0 Released 24
[ANN] RDoc 2.2.1 released 0

Members online

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top