You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Benoit Daloze edited this page Jan 23, 2019
·
6 revisions
Why should you write your next Ruby extension using ruby-ffi? Why should you consider re-implementing an existing standard extension using ruby-ffi? The section below aims to give you some good answers to these questions.
An FFI extension doesn't need compilation
You don't need a compiler installed on your system to be able to run FFI extensions. Nor do you need to install the development versions of libraries; the runtime versions will do. The libraries you link against will need to have been compiled at some point, of course, but odds are you won't have had to do it.
An FFI extension is multi-platform and multi-implementation
An FFI extension works without changes on Ruby, JRuby, TruffleRuby, and any other Ruby VM that supports FFI.
An FFI extension is easy to read
Because all the code for an FFI extension is written in Ruby, it's as easy to read as any other Ruby code. There is no need to switch mental modes from C programming to Ruby programming.
An FFI extension is easy to write
Writing a Ruby-FFI based extension is easy thanks to an intuitive DSL. For example, the snippet below is all you need to interface with the 'puts' function defined in the libc C library: