From: ptkwt@... (Phil Tomson) Date: 2006-02-09T11:13:22+09:00 Subject: Re: distributing native and ruby version of a library In article , Patrick Gundlach wrote: >Hi, > >I have a simple library, one in a pure ruby version and one in a >ruby/c version (which is quicker). I would like to distribute both and >let the user decide (by checking whether a c library is available) >which version to install. What would a clever way to accomplish that? >Should I make the decision when running extconf.rb? Any hints? > >Patrick > >(the directory structure so far) > >rb/mylib.rb > >c/mylib.rb > /mylib_base.c > /extconf.rb > >both should be used by require 'mylib' or alike. > How about in your rb/mylib.rb file you do something like: begin require 'ext/mylib_base' rescue require 'lib/mylib_base' end Where ext/mylib_base would be the shared lib created from the C file and lib/mylib_base would be the Ruby implementation. The user of mylib just does: require 'mylib' ....and it's all transparent to the user whether or not the C version or the ruby version is used. Phil