What are native extensions in Ruby?

A native extension is simply C code that needs to be compiled and that might link a Ruby gem library or component to a non-Ruby library. For instance, a Ruby gem that uses nokogiri has a C code (native extension) that interacts with nokogiri and represents a link from the Ruby gem to nokogiri.

A Ruby machine is built in C, you need to understand that every Ruby programming code is combined into instructions for the C – built Ruby virtual machine to execute. So native extensions are libraries built in the same C which Ruby was built in other to enhance the function of the gems. They are simply compiled C code that a Ruby gem needs to interact with a non-Ruby component or that needs to be run in C for speed (C code is much faster than Ruby normally).

Other articles you might like: