Take eventmachine gem for example, run:

bundle config build.eventmachine --with-cppflags=-I/usr/local/opt/openssl/include

then run

bundle install

will build.

via https://github.com/eventmachine/eventmachine/issues/602