On some machines, installing Ruby 1.8.7 with ruby-build can lead to this error:
math.c:37:13: error: missing binary operator before token "("
Try instead to install ruby-1.8.7-p374.
ruby-1.8.7-p374