Install rvm

$ curl -L https://get.rvm.io | bash -s stable --ruby

Install ruby VERSION X.X.X

$ brew update
$ brew tap homebrew/dupes
$ brew install autoconf automake apple-gcc42
$ rvm pkg install openssl
$ rvm install 1.9.3 (or `rvm reinstall all --force` in case you had already installed ruby)
$ sudo ln -s /usr/local/bin/gcc-4.2 /usr/bin/gcc-4.2