# Getting the comments(RDoc/ri) while running

**URL:** <https://www.ruby-forum.com/t/getting-the-comments-rdoc-ri-while-running/153219>\
**Category:** Ruby\
**Created:** [November 13, 2008, 4:41pm UTC](https://www.ruby-forum.com/t/getting-the-comments-rdoc-ri-while-running/153219 "2008-11-13T16:41:44Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vassilis\_R](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/848f3c/32.png) [@Vassilis\_R](https://www.ruby-forum.com/u/Vassilis_R)\
**Post date:** [November 13, 2008, 4:41pm UTC](https://www.ruby-forum.com/t/getting-the-comments-rdoc-ri-while-running/153219/1 "2008-11-13T16:41:44Z")

</div>

The problem:  
There is this parser, dynamically extensible with methods from modules.  
In very mundane fashion the methods have a standard prefix (like  
Test::Unit does it) so there is no problem getting the list of the  
methods.  
Now the methods handle elements in a DSL and there are conditions and  
parameters that each element expects. All this information is currently  
available as an RDoc comment for each method.  
Aside from making a system call to ri and grabbing the output is there  
any other clever way to grab those comment lines?  
Now, I want the comments in the RDoc so I don’t want to do something  
like the ‘desc “describe this task”’ trick that rake does.  
Any clever ideas?  
Cheers,  
V.-

---

<div class="post-metadata">

**Author:** ![Vassilis\_R](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/848f3c/32.png) [@Vassilis\_R](https://www.ruby-forum.com/u/Vassilis_R)\
**Post date:** [November 13, 2008, 5:10pm UTC](https://www.ruby-forum.com/t/getting-the-comments-rdoc-ri-while-running/153219/2 "2008-11-13T17:10:29Z")

</div>

It’s a little open-ended … I use Netbeans as my IDE when I write code,  
its code-completion feature is amazing for Ruby as well as Rails. Would  
that satisfy you? It shows a list of commands and the rdoc for it  
underneath.

–Aldric

---

<div class="post-metadata">

**Author:** ![Vassilis\_R](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/848f3c/32.png) [@Vassilis\_R](https://www.ruby-forum.com/u/Vassilis_R)\
**Post date:** [November 13, 2008, 6:43pm UTC](https://www.ruby-forum.com/t/getting-the-comments-rdoc-ri-while-running/153219/3 "2008-11-13T18:43:16Z")

</div>

On Fri, 14 Nov 2008, Vassilis R. wrote:

> OK, just to clarify a bit:  
> I use these methods in my app and they add functionality that needs specific  
> parameters and configuration. It’s an exte. The parameters are described in  
> the comments for the methods.  
> Now, I want to be able (from within my app) to display the documentation for  
> those methods. I can do it by calling `ri method_name` and grabbind the output  
> but I was wondering if there is a cleverer way (and one that does not require  
> ri to be in the path)  
> Cheers,  
> V.-

ri gets docs built with rdoc. When you build those docs with rdoc, do  
you get better results with -p?

RDoc V1.0.1 - 20041108

Usage:

rdoc [options] [names…]  
[…]  
Options:  
[…]  
–promiscuous, -p When documenting a file that contains a  
module  
or class also defined in other files, show  
all stuff for that module/class in each  
files  
page. By default, only show stuff defined in  
that particular file.

```
    Hugh
```

---

<div class="post-metadata">

**Author:** ![Vassilis\_R](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/848f3c/32.png) [@Vassilis\_R](https://www.ruby-forum.com/u/Vassilis_R)\
**Post date:** [November 13, 2008, 6:37pm UTC](https://www.ruby-forum.com/t/getting-the-comments-rdoc-ri-while-running/153219/4 "2008-11-13T18:37:57Z")

</div>

Aldric G. wrote:

> It’s a little open-ended … I use Netbeans as my IDE when I write code,  
> its code-completion feature is amazing for Ruby as well as Rails. Would  
> that satisfy you? It shows a list of commands and the rdoc for it  
> underneath.

OK, just to clarify a bit:  
I use these methods in my app and they add functionality that needs  
specific parameters and configuration. It’s an exte. The parameters are  
described in the comments for the methods.  
Now, I want to be able (from within my app) to display the documentation  
for those methods. I can do it by calling `ri method_name` and grabbind  
the output but I was wondering if there is a cleverer way (and one that  
does not require ri to be in the path)  
Cheers,  
V.-

---

<div class="post-metadata">

**Author:** ![Vassilis\_R](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/848f3c/32.png) [@Vassilis\_R](https://www.ruby-forum.com/u/Vassilis_R)\
**Post date:** [November 13, 2008, 10:23pm UTC](https://www.ruby-forum.com/t/getting-the-comments-rdoc-ri-while-running/153219/5 "2008-11-13T22:23:23Z")

</div>

On Nov 13, 2008, at 09:34 , Vassilis R. wrote:

> I can do it by calling `ri method_name` and grabbind the output but  
> I was wondering if there is a cleverer way (and one that does not  
> require ri to be in the path)

you can certainly access the data directly. look at rdoc/ri/  
driver.rb… thar be dragons.

---

<div class="post-metadata">

**Author:** ![Vassilis\_R](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/848f3c/32.png) [@Vassilis\_R](https://www.ruby-forum.com/u/Vassilis_R)\
**Post date:** [November 13, 2008, 11:12pm UTC](https://www.ruby-forum.com/t/getting-the-comments-rdoc-ri-while-running/153219/6 "2008-11-13T23:12:06Z")

</div>

On Nov 13, 2008, at 3:19 PM, Ryan D. wrote:

> > I can do it by calling `ri method_name` and grabbind the output but  
> > I was wondering if there is a cleverer way (and one that does not  
> > require ri to be in the path)
> 
> you can certainly access the data directly. look at rdoc/ri/  
> driver.rb… thar be dragons.

If all you want is the comment, you could also just use caller() to  
find the line number and source file containing the method, open that  
file, and scan backwards from the method definition…

---

<div class="post-metadata">

**Author:** ![Vassilis\_R](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/848f3c/32.png) [@Vassilis\_R](https://www.ruby-forum.com/u/Vassilis_R)\
**Post date:** [November 14, 2008, 5:48pm UTC](https://www.ruby-forum.com/t/getting-the-comments-rdoc-ri-while-running/153219/7 "2008-11-14T17:48:26Z")

</div>

For that exact thing, check out Lazydoc ([http://tap.rubyforge.org/](http://tap.rubyforge.org/)  
lazydoc/). Lazydoc allows you to register lines at which to pull out  
documentation, as well as lazy class attributes whose values are  
pulled from the documentation as needed.

require ‘rubygems’  
require ‘lazydoc’

class Sample

# comment for method one

def method\_one  
end  
end

doc = Lazydoc[**FILE**]

# register by line counting from 0

# or using a regexp

#comment = doc.register(5)  
comment = doc.register(/method\_one/)

doc.resolve  
puts comment.subject # =\> " def method\_one"  
puts comment.content # =\> “comment for method one”

(Note the lazy attributes aren’t shown, but examples are in the  
documentation)
