See https://github.com/rbenv/ruby-build/wiki
Assuming rbenv and ruby-build already setup
brew install openssl libyaml libffi readline
# required for building Ruby <= 1.9.3-p0:
brew tap homebrew/dupes && brew install apple-gcc42
brew install https://github.com/Homebrew/homebrew-versions/raw/586b7e9012a3ed1f9df6c43d0483c65549349289/openssl098.rb
# LDFLAGS/CPPFLAGS/PKG_CONFIG_PATH output by `brew install ../openssl098.rb`
LDFLAGS="-L/usr/local/opt/openssl098/lib" CPPFLAGS="-I/usr/local/opt/openssl098/include" PKG_CONFIG_PATH="/usr/local/opt/openssl098/lib/pkgconfig" RUBY_CONFIGURE_OPTS=--with-readline-dir="$(brew --prefix readline)" rbenv install 1.8.7-p352