Getting the comments(RDoc/ri) while running

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.-

···

--
http://www.braveworld.net/riva

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

Vassilis Rizopoulos wrote:

···

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.-

Aldric Giacomoni 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.-

···

--Aldric

Vassilis Rizopoulos wrote:
  

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.-
    
--
http://www.braveworld.net/riva

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

···

On Fri, 14 Nov 2008, Vassilis Rizopoulos 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.-

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

···

On Nov 13, 2008, at 09:34 , Vassilis Rizopoulos 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)

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...

···

On Nov 13, 2008, at 3:19 PM, Ryan Davis 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.

For that exact thing, check out Lazydoc (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)