The Ruby Bindings Every Rails Developer Should Know

December 3, 2025

By Germán Silva

Bindings are one of the most underrated yet critical pieces of the Ruby ecosystem. They are the bridges that connect Ruby to native libraries, databases, protocols, and even hardware.

Bring Your Next Project to Life with High-Quality Development

Don’t miss the opportunity to take your project to the next level. Whether you want to launch something new or improve an existing platform, we build maintainable, scalable software that empowers your business.

Get in touch — Start your project 🚀 Available for freelance and team-based projects • Fast replies

If you work with Ruby on Rails, APIs, or IoT integrations, mastering these bindings dramatically improves performance, scalability, and the systems you can build.

Here’s a guide to the most important bindings in 2026 — with real code examples.

Article content

1. Database Bindings

PostgreSQL — pg

Ruby’s most widely used production database binding.

require "pg"

conn = PG.connect(dbname: "mydb")
rows = conn.exec("SELECT * FROM users")
rows.each { |r| puts r["email"] }

MySQL — mysql2

require "mysql2"

client = Mysql2::Client.new(host: "localhost", username: "root")
client.query("SELECT NOW()").each { |r| puts r }

Redis — redis-rb

Used everywhere: caching, sessions, Sidekiq, ActionCable.

require "redis"

redis = Redis.new
redis.set("counter", 1)
puts redis.get("counter")

2. Native Extensions (C Bindings)

Nokogiri (libxml2)

Fast HTML/XML parsing.

require "nokogiri"

html = Nokogiri::HTML("<h1>Hello</h1>")
puts html.css("h1").text

Oj (fast JSON parser)

Drop-in replacement for json.

require "oj"

json = Oj.dump({ name: "Germán", ok: true })
data = Oj.load(json)
puts data["name"]

ruby-vips (libvips)

Ultra-fast image processing.

require "vips"

image = Vips::Image.new_from_file("photo.jpg")
thumbnail = image.thumbnail_image(200)
thumbnail.write_to_file("thumb.jpg")

Typhoeus (libcurl)

Highly concurrent HTTP requests.

require "typhoeus"

response = Typhoeus.get("https://api.example.com")
puts response.body

3. Protocol Bindings (Web, Realtime & IoT)

ActionCable (WebSockets in Rails)

# app/channels/chat_channel.rb
class ChatChannel < ApplicationCable::Channel
  def subscribed
    stream_from "chat"
  end
end

gRPC for Ruby

require "grpc"
MyServiceStub = MyApi::Service::Stub

client = MyServiceStub.new("localhost:50051", :this_channel_is_insecure)
response = client.get_status(MyApi::StatusRequest.new)

MQTT — ruby-mqtt (perfect for IoT + ESP32)

require "mqtt"

MQTT::Client.connect("mqtt://localhost") do |client|
  client.subscribe("esp32/motion")
  client.get do |topic, message|
    puts "Received: #{topic} - #{message}"
  end
end

This is the exact pattern I use when my ESP32 devices publish sensor events to a Ruby backend.


4. Language / Runtime Interop

mini_racer (V8 engine inside Ruby)

require "mini_racer"

ctx = MiniRacer::Context.new
puts ctx.eval("1 + 2")

JRuby (Ruby on JVM)

java_import java.util.Date
puts Date.new

Rutie (Ruby + Rust)

A very small example just to illustrate usage:

#[macro_use]
extern crate rutie;

class!(Hello);

methods!(
  Hello,
  _itself,
  fn say_hello() -> RString {
    RString::new_utf8("Hello from Rust!")
  }
);

Ruby side:

require "hello"
puts Hello.say_hello

5. Hardware & Embedded Bindings

ruby-serialport

require "serialport"

sp = SerialPort.new("/dev/ttyUSB0", 115200)
sp.write("ping")

rpi_gpio (Raspberry Pi GPIO)

require "rpi_gpio"

RPi::GPIO.set_numbering :bcm
RPi::GPIO.setup 18, as: :output
RPi::GPIO.set_high 18

Final Thoughts

Bindings are the hidden power behind Ruby’s speed, scalability, and real-world integration capabilities. By mastering them, you unlock the ability to build:

  • high-throughput Rails APIs
  • real-time dashboards
  • efficient image-heavy applications
  • IoT systems powered by ESP32/ESP8266
  • distributed services using gRPC, Redis, or Kafka
  • hardware-enabled automation

If you want to grow as a Ruby developer in 2026, learn the bindings that connect Ruby to the world.

Article content

Leave a comment