# RDoc and SWIG

**URL:** <https://rubytalk.org/t/rdoc-and-swig/18586>\
**Category:** ruby-talk\
**Created:** [23 May 2005 18:17 UTC](https://rubytalk.org/t/rdoc-and-swig/18586 "2005-05-23T18:17:01Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gennady1](https://avatars.discourse-cdn.com/v4/letter/g/a4c791/32.png) [@Gennady1](https://rubytalk.org/u/Gennady1)\
**Post date:** [23 May 2005 18:17 UTC](https://rubytalk.org/t/rdoc-and-swig/18586/1 "2005-05-23T18:17:01Z")

</div>

Hi, rubyists

I use SWIG to wrap C++ classes into Ruby. Is there any way to use RDoc comments in the original C++ classes to generate documentation for ruby API? From what I can see, RDoc looks for rb\_define\_class() and rb\_define\_method() to extract classes and methods to be documented, however those are generated by SWIG in the build phase.

RDoc understands "Document-class" and "Document-metnod" directives, however those seem to be taken into account only after a class or a method is extracted from rb\_define\_class()/rb\_define\_method().

Are there any directives (or any plans to add them) that would allow to directly specify that the RDoc comment is for a particular class or a particular class/instance method?

Thank you,  
Gennady Bystritsky.

---

<div class="post-metadata">

**Author:** ![Sam\_Roberts1](https://avatars.discourse-cdn.com/v4/letter/s/ed8c4c/32.png) [@Sam\_Roberts1](https://rubytalk.org/u/Sam_Roberts1)\
**Post date:** [23 May 2005 23:52 UTC](https://rubytalk.org/t/rdoc-and-swig/18586/2 "2005-05-23T23:52:05Z")

</div>

Quoting gfb@tonesoft.com, on Tue, May 24, 2005 at 03:17:01AM +0900:

> Hi, rubyists
> 
> I use SWIG to wrap C++ classes into Ruby. Is there any way to use RDoc  
> comments in the original C++ classes to generate documentation for ruby  
> API? From what I can see, RDoc looks for rb\_define\_class() and  
> rb\_define\_method() to extract classes and methods to be documented,  
> however those are generated by SWIG in the build phase.

I would be surprised if this works, but you might get lucky.

If you don't get lucky, a DDJ article of a few months back described a  
way of using doxygen with visual basic, that might apply to documenting  
c++ with rdoc. Basically, run a script converting the C++ to something  
that looks like ruby. It doesn't have to be ruby, you can remove all the  
code inside methods, for example, but enough like ruby that rdoc will  
process the file and generate API docs.

Sam

---

<div class="post-metadata">

**Author:** ![Lothar\_Scholz2](https://avatars.discourse-cdn.com/v4/letter/l/f14d63/32.png) [@Lothar\_Scholz2](https://rubytalk.org/u/Lothar_Scholz2)\
**Post date:** [25 May 2005 14:03 UTC](https://rubytalk.org/t/rdoc-and-swig/18586/3 "2005-05-25T14:03:19Z")

</div>

Hello Gennady,

> Hi, rubyists

> I use SWIG to wrap C++ classes into Ruby. Is there any way to use RDoc

When using SWIG and Ruby do the that FXRuby does. Generate a complete  
stub set of ruby files only for the purpose of generating RDOC  
documentation. This duplicates information but is still the best way.

> **···**
>
> --  
> Best regards, emailto: scholz at scriptolutions dot com  
> Lothar Scholz [http://www.ruby-ide.com](http://www.ruby-ide.com)  
> CTO Scriptolutions Ruby, PHP, Python IDE 's

---

<div class="post-metadata">

**Author:** ![Gennady1](https://avatars.discourse-cdn.com/v4/letter/g/a4c791/32.png) [@Gennady1](https://rubytalk.org/u/Gennady1)\
**Post date:** [24 May 2005 02:37 UTC](https://rubytalk.org/t/rdoc-and-swig/18586/4 "2005-05-24T02:37:17Z")

</div>

> Quoting gfb@tonesoft.com, on Tue, May 24, 2005 at 03:17:01AM +0900:
> 
> > Hi, rubyists
> > 
> > I use SWIG to wrap C++ classes into Ruby. Is there any way to use RDoc  
> > comments in the original C++ classes to generate documentation for ruby  
> > API? From what I can see, RDoc looks for rb\_define\_class() and  
> > rb\_define\_method() to extract classes and methods to be documented,  
> > however those are generated by SWIG in the build phase.
> 
> I would be surprised if this works, but you might get lucky.
> 
> If you don't get lucky, a DDJ article of a few months back described a  
> way of using doxygen with visual basic, that might apply to documenting  
> c++ with rdoc. Basically, run a script converting the C++ to something  
> that looks like ruby. It doesn't have to be ruby, you can remove all the  
> code inside methods, for example, but enough like ruby that rdoc will  
> process the file and generate API docs.
> 
> Sam

Interesting. However, it sounds like a lot of hassle. I took another approach, though. I need some pure Ruby methods in my wrapped classes anyways, so even for the methods implemented in C++, I add a pure Ruby method (honoring ruby name conventions, otherwise achieved by SWIG %rename directive), from where I simply delegate to my corresponding C++ methods, witch I make private. This gives me the opportunity to document the methods naturally, for the cost of extra redirection.

Thanks, Sam.  
Gennady.

> **···**
>
> On May 23, 2005, at 16:52, Sam Roberts wrote:

---

<div class="post-metadata">

**Author:** ![Gennady1](https://avatars.discourse-cdn.com/v4/letter/g/a4c791/32.png) [@Gennady1](https://rubytalk.org/u/Gennady1)\
**Post date:** [25 May 2005 14:12 UTC](https://rubytalk.org/t/rdoc-and-swig/18586/5 "2005-05-25T14:12:46Z")

</div>

Lothar Scholz wrote:

> Hello Gennady,
> 
> \> Hi, rubyists
> 
> \> I use SWIG to wrap C++ classes into Ruby. Is there any way to use RDoc
> 
> When using SWIG and Ruby do the that FXRuby does. Generate a complete  
> stub set of ruby files only for the purpose of generating RDOC  
> documentation. This duplicates information but is still the best way.

That's, actually, what I ended up with, on my own ;-). Thanks.

Gennady.
