This example illustrates how you can hook Ruby to a very simple C program containing a function and a global variable.
/* File : example.c */
/* A global variable */
double Foo = 3.0;
/* Compute the greatest common divisor of positive integers */
int gcd(int x, int y) {
  int g;
  g = y;
  while (x > 0) {
    g = x;
    x = y % x;
    y = g;
  }
  return g;
}
/* File: example.i */ %module example extern int gcd(int x, int y); extern double Foo;
require 'example'
g = Example.gcd(42,105)
a = Example.Foo