# About ruby/ext/my\_extension/lib function

**URL:** <https://www.ruby-forum.com/t/about-ruby-ext-my-extension-lib-function/177794>\
**Category:** Ruby\
**Created:** [October 23, 2009, 8:51pm UTC](https://www.ruby-forum.com/t/about-ruby-ext-my-extension-lib-function/177794 "2009-10-23T20:51:49Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ravishi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/9dc877/32.png) [@ravishi](https://www.ruby-forum.com/u/ravishi)\
**Post date:** [October 23, 2009, 8:51pm UTC](https://www.ruby-forum.com/t/about-ruby-ext-my-extension-lib-function/177794/1 "2009-10-23T20:51:49Z")

</div>

What is the right structure for a Ruby extension? I mean, not a RubyGem,  
a Ruby extension like that openssl one that comes with Ruby source.

I’ve asked in the IRC channel and all that the people said was: “just  
put it under ruby/ext”. But some extensions (openssl, for example) have  
a structure like that:

ruby/ext/openssl/ _lots of C files_  
ruby/ext/openssl/lib/openssl.rb  
ruby/ext/openssl/lib/openssl/ _some Ruby files_

My question is: what are these Ruby files for?

I want to know because I want to compile Rubygame (a RubyGem) like if it  
was a common Ruby extension in order to link it statically with an  
embedded application and run it on my handheld. And on rubygame source  
exists a lib dir with files that are needed by the rubygame.

Thank you for the help

---

<div class="post-metadata">

**Author:** ![ravishi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/9dc877/32.png) [@ravishi](https://www.ruby-forum.com/u/ravishi)\
**Post date:** [October 27, 2009, 4:10pm UTC](https://www.ruby-forum.com/t/about-ruby-ext-my-extension-lib-function/177794/2 "2009-10-27T16:10:32Z")

</div>

Ravish Inverse wrote:

> What is the right structure for a Ruby extension? I mean, not a RubyGem,  
> a Ruby extension like that openssl one that comes with Ruby source.
> 
> I’ve asked in the IRC channel and all that the people said was: “just  
> put it under ruby/ext”. But some extensions (openssl, for example) have  
> a structure like that:
> 
> ruby/ext/openssl/ _lots of C files_  
> ruby/ext/openssl/lib/openssl.rb  
> ruby/ext/openssl/lib/openssl/ _some Ruby files_
> 
> My question is: what are these Ruby files for?
> 
> I want to know because I want to compile Rubygame (a RubyGem) like if it  
> was a common Ruby extension in order to link it statically with an  
> embedded application and run it on my handheld. And on rubygame source  
> exists a lib dir with files that are needed by the rubygame.
> 
> Thank you for the help

Those ruby files (the ones under the lib directory) are just like the  
class / module definitions in any other gem; in this case, some of them  
happen to be written in ruby (by convention these are put inside the lib  
directory) and some in C (by convention, native extensions go in an ext  
directory). When a gem gets installed and the native code compiled, the  
end user treats them in the same way, regardless of what language  
they’ve been written in.

If your native extension is heinously complicated you might want to  
organise the files into sub folders in ext, and tweak your extconf.rb.
