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 797561
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T22:49:34+00:00 2026-05-14T22:49:34+00:00

I would like to see some source code or maybe a link to some

  • 0

I would like to see some source code or maybe a link to some that gives at least a stub for writing ruby gems in the C languages (C++?? is that possible too?)

Also, some of you may know that Facebook compiles some of their code natively as php extensions for better performance. Is anyone doing this in Rails? If so, what has been your experience with it? Have you found it to be useful?

Thanks.

Edit:
I guess I’ll answer my own question with some stuff I learned today but I’m going to leave the question open for another answer because I’d like to see what others have to say on this topic

  • 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-05-14T22:49:35+00:00Added an answer on May 14, 2026 at 10:49 pm

    Ok, so I sat down a buddy of mine that is good with C. I have been showing him Ruby and he digs it. When we met last night I told him that you could write Ruby gems in C, which intrigued him. Here is what we found:

    Tutorials/Examples

    http://www.eqqon.com/index.php/Ruby_C_Extension

    http://drnicwilliams.com/2008/04/01/writing-c-extensions-in-rubygems/

    http://www.rubyinside.com/how-to-create-a-ruby-extension-in-c-in-under-5-minutes-100.html

    ruby-doc (ruby.h source code)

    http://ruby-doc.org/doxygen/1.8.4/ruby_8h-source.html

    Here is some source code that we wrote to test it out as well:

    Open up a terminal:

    prompt>mkdir MyTest
    prompt>cd MyTest
    prompt>gedit extconf.rb
    

    Then you put this code in extconf.rb

    # Loads mkmf which is used to make makefiles for Ruby extensions
    require 'mkmf'
    
    # Give it a name
    extension_name = 'mytest'
    
    # The destination
    dir_config(extension_name)
    
    # Do the work
    create_makefile(extension_name)
    

    Save the file then write MyTest.c

    #include "ruby.h"
    
    // Defining a space for information and references about the module to be stored internally
    VALUE MyTest = Qnil;
    
    // Prototype for the initialization method - Ruby calls this, not you
    void Init_mytest();
    
    // Prototype for our method 'test1' - methods are prefixed by 'method_' here
    VALUE method_test1(VALUE self);
    VALUE method_add(VALUE, VALUE, VALUE);
    
    // The initialization method for this module
    void Init_mytest() {
    MyTest = rb_define_module("MyTest");
    rb_define_method(MyTest, "test1", method_test1, 0);
    rb_define_method(MyTest, "add", method_add, 2);
    }
    
    // Our 'test1' method.. it simply returns a value of '10' for now.
    VALUE method_test1(VALUE self) {
    int x = 10;
    return INT2NUM(x);
    }
    
    // This is the method we added to test out passing parameters
    VALUE method_add(VALUE self, VALUE first, VALUE second) {
    int a = NUM2INT(first);
    int b = NUM2INT(second);
    return INT2NUM(a + b);
    }
    

    From the prompt you then need to create a Makefile by running extconf.rb:

    prompt>ruby extconf.rb
    prompt>make
    prompt>make install
    

    You can then test it out:

    prompt>irb
    irb>require 'mytest'
    irb>include MyTest
    irb>add 3, 4 # => 7
    

    We did a benchmark test and had ruby add 3 and 4 together 10 million times and then make a call to our C extension 10 million times as well. The result was that using only ruby it took 12 seconds to complete this task while using the C extension only took 6 seconds! Also note, that most of this processing is handing the job off to C to complete the task. In one of those tutorials the writer used recursion (Fibonacci sequence) and reported that the C extension took 51 times faster!

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

Sidebar

Ask A Question

Stats

  • Questions 405k
  • Answers 405k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer If I wanna get a "filtered" subset of the item… May 15, 2026 at 5:53 am
  • Editorial Team
    Editorial Team added an answer Add %L in the command line for the application you… May 15, 2026 at 5:52 am
  • Editorial Team
    Editorial Team added an answer That's possible. The host (address/port) you're doing the request to… May 15, 2026 at 5:52 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.