I just had the same problem and one solution is currently to use apple-gcc42 instead of clang to compile both gems :
brew install apple-gcc42
And then you have the choice between doing some symlinks in /usr/bin for {gcc,g++,c++} binaries :
sudo ln -s /usr/local/Cellar/apple-gcc42/4.2.1-5666.3/bin/gcc-4.2 /usr/bin/gcc
sudo ln -s /usr/local/Cellar/apple-gcc42/4.2.1-5666.3/bin/g++-4.2 /usr/bin/g++
sudo ln -s /usr/local/Cellar/apple-gcc42/4.2.1-5666.3/bin/cpp-4.2 /usr/bin/cpp
In fact g++ should be enough.
Or...you could export CC/CXX/CPP environment variables with paths corresponding to the binaries created by homebrew. That's surely a cleaner workaround.
A third solution is to download Xcode 4.6.3 and install it in the Applications folder. Then, enter in the terminal:
sudo xcode-select --switch /Applications/Xcode4.6.3.app/Contents/Developer
gem install therubyracer
Once the gem has been installed you can switch back to Xcode 5.0 :
sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer