

This is made possible by the RubyInline gem, which can be installed using the command: The first approach we’ll look at is including inline C++ code in a Ruby script. This post looks at several ways we can extend Ruby using native code:įor each of these, we’ll work through an example, look at some pros and cons, and the degree to which C++ is supported. The Definitive Guide to Ruby’s C API goes into much more detail about this (and much more).

Since Ruby is a dynamicly-typed, object-oriented language, with garbage collection built into the VM, it requires a different kind of thinking than regular C++ development. As C++ programmers, what do we need to know to write high quality Ruby extensions? Ruby Throughout this post, we’ll look at several examples, all of which are available on Github.
#How to write c code within ruby how to
This post takes the idea a step further, and looks at how to extend Ruby with C++. We saw how C can be used to enhance the functionality of the Ruby language. In my previous post, I covered the basics of writing a Ruby gem with native extensions.
