Modified from https://github.com/sstephenson/ruby-build/wiki
Install XQuartz
Install Homebrew (if you don't have it already)
brew tap homebrew/dupes (repository for duplicate system tools)
brew install apple-gcc42
export CPPFLAGS=-I/opt/X11/include
CONFIGURE_OPTS="--with-readline-dir=/usr/local/Cellar/readline/6.2.4" CC=/usr/local/bin/gcc-4.2 ruby-build -kv 1.8.7-p371 ~/.rubies/ruby-1.8.7-p371