Still Curious, Still Learning

Enjoying life as it is, changing it when I can.

C Ruby

Summary: getting to know how C is used in Ruby and the synergies between them:

  • Understanding Ruby
  • Speeding up Ruby
  • Accessing non-Ruby libraries.

Details follow:

Understand Ruby

Some things you can only find out from reading the C code.

Speed Up Ruby

  • Rewrite parts of your code in C
  • 20x-50x speed gain.

C Extensions

Ruby + C

Best of both worlds

Level 1 — build Ruby from scratch

ruby-2.0.0-p247 is stable

Configure (Mac)

1
2
3
$ brew install openssl
$ autoconf
$ ./configure --prefix= $HOME/myruby --with--opot-dir=/usr/l...

creates lots of output.

compile and Build

1
$ make

Then check it

1
$ make check

Then install it

1
$ make install

Setup PATHSs

  1. Include your new ruby in $PATH. …

Verify

1
$ which ruby

gem env

Can check further by installing Rails

Can even set up in RubyMine

Level 2 – Debugger

lldb – he showed how to use this debugger to see how you walk in C.

Can use XCode lldb

Folder Structure

ext and the root folder are the most interesting.

Level 4 – Hacking

Epilog

  • ruby internals
  • ruby metaprogramming
  • ruby object model

and the rest I didn’t get.