David Vallner
2/9/2006 2:15:00 AM
Well, last guess before I head to bed:
In "mylib.rb":
begin
require "mylib_impl_c" # Attempts to load the C shared library.
rescue LoadError
require "mylib_impl_rb" # Falls back to the ruby implementation.
end
Yay for gracefully degrading functionality. Or performance, for that matter.
Sprinkle with configuration parameters to let user determine at runtime which
backend to use to taste.
David Vallner
Dna Streda 08 Február 2006 20:58 Patrick Gundlach napísal:
> 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.