Using Gems through proxy with authentication

I am trying to use rubygems to install rails but I am behind a proxy
that requires authentication.

I am trying to use the following:

gem install rails --include-dependencies -p (I have HTTP_PROXY set
to 'http://myurl:8080'

I get the following error

ERROR: While executing gem ... (Gem::RemoteSource Exception)
        HTTP Response 407

I need to authenticate on the proxy server with a username/pass but
cannot find any documentation showing how to pass this to the proxy.

Any ideas?