You will need a C compiler to install Ruby. Download and install the pre-build binary for your version of OS X. If you're not sure what version of OS X you're using, go to the menu and select "About This Mac".
https://github.com/kennethreitz/osx-gcc-installer#option-1-downloading-pre-built-binaries
Open Applications > Utilities > Terminal.app and paste in the following command:
ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go)"
After Homebrew is installed, use it to update your version of Ruby:
brew install ruby
After that finishes, enter this command to set your default ruby
version:
echo 'export PATH="/usr/local/opt/ruby/bin:$PATH"' >> ~/.bash_profile
Then quit and restart Terminal.app.
After Ruby is updated, install the latest version of Rails:
gem install rails