Forum: Ruby Getting the comments(RDoc/ri) while running

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Vassilis R. (Guest)
on 2008-11-13 17:41
(Received via mailing list)
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 G. (Guest)
on 2008-11-13 18:10
(Received via mailing list)
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 R. (Guest)
on 2008-11-13 19:37
(Received via mailing list)
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.-
Hugh S. (Guest)
on 2008-11-13 19:43
(Received via mailing list)
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
Ryan D. (Guest)
on 2008-11-13 23:23
(Received via mailing list)
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.
Dave T. (Guest)
on 2008-11-14 00:12
(Received via mailing list)
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...
Simon C. (Guest)
on 2008-11-14 18:48
(Received via mailing list)
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)
This topic is locked and can not be replied to.