# Rdoc and constructs like DL::Import's extern

**URL:** <https://www.ruby-forum.com/t/rdoc-and-constructs-like-dl-imports-extern/98196>\
**Category:** Ruby\
**Created:** [July 13, 2006, 12:42am UTC](https://www.ruby-forum.com/t/rdoc-and-constructs-like-dl-imports-extern/98196 "2006-07-13T00:42:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sevensoft](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/f9ae1b/32.png) [@sevensoft](https://www.ruby-forum.com/u/sevensoft)\
**Post date:** [July 13, 2006, 12:42am UTC](https://www.ruby-forum.com/t/rdoc-and-constructs-like-dl-imports-extern/98196/1 "2006-07-13T00:42:35Z")

</div>

I’m wrapping a C library (link-grammar, to be specific) in an  
object-oriented ruby interface using DL::Import. The library is a very  
well designed object-oriented C library, which is to say it uses very  
consistent naming and calling conventions. Thus, the library lends  
itself very well to automation when wrapping the the library in  
object-oriented code.

I use DL::Import to create a CLib module containing all of the  
functions in the C library. (Actually, I’ve wrapped extern in another  
function which automatically defines certain things like safe string  
handling where necessary, and automatic assignment of free functions)

In the various classes which call the functions in CLib, there was  
also a lot to be gained by writing an extern-like function to automate  
the work. For example, in the ParseOptions class,

class ParseOptions  
def initialize  
@optsptr=CLib.parse\_options\_create()  
end  
attr\_reader :optsptr  
class \<\<self  
def option(\*names)  
names.each do |name|  
class\_eval \<\<-“end;”  
def #{name}  
CLib.parse\_options\_get\_#{name}(@optsptr)  
end  
def #{name}=(val)  
CLib.parse\_options\_set\_#{name}(@optsptr,val.to\_i)  
end  
end;  
end  
end  
private :option  
end  
option :verbosity, :linkage\_limit, :disjunct\_cost  
option :min\_null\_count, :max\_null\_count, :null\_block  
option :islands\_ok, :short\_length, :max\_memory  
option :max\_sentence\_length, :max\_parse\_time  
option :cost\_model\_type, :screen\_width, :allow\_null  
option :display\_walls, :all\_short\_connectors, :batch\_mode  
option :panic\_mode, :display\_on, :display\_postscript  
option :display\_constituents, :display\_bad, :display\_links  
option :display\_union, :echo\_on  
end

Is there any way to get rdoc to document all of the methods that the  
option method automatically creates?

I have noticed that rdoc doesn’t even know how to do it for the methods  
created by DL::Import.extern. (I haven’t worked with rails, but I  
imagine rails has a similar problem.)

–Ken B.

---

<div class="post-metadata">

**Author:** ![sevensoft](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/f9ae1b/32.png) [@sevensoft](https://www.ruby-forum.com/u/sevensoft)\
**Post date:** [July 13, 2006, 1:01am UTC](https://www.ruby-forum.com/t/rdoc-and-constructs-like-dl-imports-extern/98196/2 "2006-07-13T01:01:12Z")

</div>

On Jul 12, 2006, at 6:40 PM, Ken B. wrote:

> Is there any way to get rdoc to document all of the methods that the  
> option method automatically creates?
> 
> I have noticed that rdoc doesn’t even know how to do it for the  
> methods  
> created by DL::Import.extern. (I haven’t worked with rails, but I  
> imagine rails has a similar problem.)

You could maybe make stubs for documentation purposes:

e.g. In some file parseoptions\_doc.rb (that doesn’t ever even get  
included)

class ParseOptions

# This method frobinates the baz

def max\_sentence\_length(baz)  
end

# this method somethings the whodinger

def cost\_model\_type  
end  
end

You just don’t use this file in your actual code but when you run  
rdoc over it, it should pick up the methods

---

<div class="post-metadata">

**Author:** ![sevensoft](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/f9ae1b/32.png) [@sevensoft](https://www.ruby-forum.com/u/sevensoft)\
**Post date:** [July 13, 2006, 7:36pm UTC](https://www.ruby-forum.com/t/rdoc-and-constructs-like-dl-imports-extern/98196/3 "2006-07-13T19:36:40Z")

</div>

Logan C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> # this method somethings the whodinger
> 
> def cost\_model\_type  
> end  
> end
> 
> You just don’t use this file in your actual code but when you run  
> rdoc over it, it should pick up the methods

Then I still have to write all of the stubs. Although I suppose I  
could make it automatically generated somehow.

–Ken B.
