To extract files from a .tar.gz file you can use the following methods from packages distributed with Ruby:
tar_extract = Gem::Package::TarReader.new(Zlib::GzipReader.open('Path/To/myfile.tar.gz'))
tar_extract.rewind # The extract has to be rewinded after every iteration
tar_extract.each do |entry|
# puts entry.read
Each entry of type Gem::Package::TarReader::Entry points to a file or directory within the .tar.gz file.
Similar code can be used (replace Reader with Writer) to write files to a .tar.gz file.