Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8917499
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T05:29:53+00:00 2026-06-15T05:29:53+00:00

I want to make a gem, and when someone else tries to use it

  • 0

I want to make a gem, and when someone else tries to use it with MRI it will use C code, and when they use it from JRuby it will use Java code.

The nokogiri and puma gems do this, and I’ve glanced at their code, but didn’t see how they were making it happen.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T05:29:55+00:00Added an answer on June 15, 2026 at 5:29 am

    This is done by cross-compiling the gem for the different platforms you are targeting, using rvm (or other similar tools to switch between rubies) and rake-compiler.

    The gemspec file must specify the files needed for each platform; this is done by checking the platform the gem is being compiled with:

    Gem::Specification.new do |gem|
    # . . .
    
      if RUBY_PLATFORM =~ /java/
        # package jars
        gem.files += ['lib/*.jar']
        # . . . 
      else
        # package C stuff
        gem.files += Dir['ext/**/*.c']
        # . . . 
        gem.extensions = Dir['ext/**/extconf.rb']
      end
    end
    

    In the Rakefile, after installing rake-compiler, the pattern is usually the following:

    spec = Gem::Specification.load('hello_world.gemspec')
    
    if RUBY_PLATFORM =~ /java/
      require 'rake/javaextensiontask'
      Rake::JavaExtensionTask.new('hello_world', spec)
    else
      require 'rake/extensiontask'
      Rake::ExtensionTask.new('hello_world', spec)
    end
    

    But you may need to do specific tasks for the different platforms.

    With MRI, you then compile with rake native gem; with JRuby, rake java gem – this is where a tool like rvm gets handy. You finally end up with different gem files for your gem, one per platform, that you can then release as your gem.

    See rake-compiler documentation for more details, or check out other projects that do the same, such as redcloth or pg_array_parser (I find they are better examples than nokogiri for this).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to make use of jQuery in Rails 2. What is the gem
I want make a bash script which returns the position of an element from
I want to convert rails plugin into gem. Is there any way to make
I want to style my Excel table using spreadsheet gem. I want to make
Is there a gem or way to display charts from Google Analytics? I want
I want to make only one page request ssl certificate. I tried to use
I'm using the Savon gem to make a SOAP request using code similar to
I want to use memcached gem (http://fauna.github.com/fauna/memcached/) on Mac OS X Lion (10.7.2). The
I'm using RoR 3.0.8 and the gem acts_as_taggable_on. I want to make it so
I want make datetimepicker in my project. Using jquery how it is possible? I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.