Permalink
Browse files

Better require example for fat-binaries

This example works for any platform and any type of gem provided
by developer (fat binaries or not, compiled or not).
  • Loading branch information...
1 parent 9b93b67 commit 7d0cb02d0e52a381e701277a83ba9ac21283d98d @luislavena luislavena committed Feb 11, 2011
Showing with 14 additions and 3 deletions.
  1. +14 −3 README.rdoc
View
@@ -326,10 +326,21 @@ NOTE: building "fat" gems is currently only supported by rake-compiler when
cross compiling from a Linux or OSX host. Patches are welcome if building
"fat" gems from Windows hosts is desired, or natively for your platform :-)
-Now is up to you to make your gem load the proper binary at runtime. Here's a hint ;-)
+Now is up to you to make your gem load the proper binary at runtime:
- RUBY_VERSION =~ /(\d+.\d+)/
- require "#{$1}/my_extension"
+ begin
+ RUBY_VERSION =~ /(\d+.\d+)/
+ require "#{$1}/my_extension"
+ rescue LoadError
+ require "my_extension"
+ end
+
+The above technique will lookup first for 1.8 or 1.9 version of the extension
+and when not found, will look for the plain extension.
+
+This approach catch the cases of provided fat binaries or gems compiled by the
+end user installing the gem. It has also been implemented successfully in
+several projects.
=== What are you talking about? (Give me examples)

0 comments on commit 7d0cb02

Please sign in to comment.