+4  A: 
Dir.chdir(dest) do
  # code that shall be executed while in the dest directory
end

Dir.chdir when invoked with a block will change to the given directory, execute the block and then change back.

You can also use it without a block, in which case it will never change back.

sepp2k
Sweet. Worked like a charm. Thanks!
Chip Castle
+1  A: 

Yes. Use Dir.chdir:

#!/usr/bin/ruby

  dest = "#{File.dirname(__FILE__)}/../build"
  package = "foo"

  Dir.chdir dest
  [
    "tar czvf data.tar.gz bin console data.sql etc filter install.rb",
    "tar czvf control.tar.gz control",
    "echo 2.0 > debian-binary",
    "ar -cr #{package}.deb debian-binary control.tar.gz data.tar.gz",
    "mv #{package}.deb ..",
    "rm data.tar.gz control.tar.gz",
  ].each do |command|
    puts command
    system(command)
  end
Adrian