Extracting Gem Through Ruby Code

When I attempt to install rails (or any gem)i get ERROR could not find a
valid gem xxxx ()=0 here is why: Unable to download data from
https://rubygems.org/- to many connection resets (url of gem)

Is there a way to extract a gem file in ruby code