Try to install X11 via http://xquartz.macosforge.org/landing/ set the correct path to the X11 library for the compiler with:
export CPPFLAGS=-I/opt/X11/include
then try to reinstall ruby, passing to the compiler where gcc-4.2 is:
CC=/usr/local/bin/gcc-4.2 rvm reinstall 1.8.7
Without CC
I got a lot of segmentation faults.