+1  A: 
  1. Use capital letters for your constants (HOME_DIR_PATH, not home_dir_path)
  2. Put your methods inside a module.

You can call your methods through the module, or you can include the module in your namespace and call them directly (Sarah has code for all of this)

Michael Sofaer
Thanks!For the benefit of others that come across this, it looks like the constants (yes, I should have said "constants" in the question, not "variables") can stay outside the module definition.Also, after putting the methods inside a module, I had to use an additional "include" statement to include that module in scripts that make use of its functions.
Charlie
Yeah, I wouldn't put constants like that in the module, since they aren't likely to cause collisions in your use case.
Michael Sofaer
+5  A: 

Wrap your methods and variables in a module, e.g.

module CommonStuff
    USERNAME=ENV['USER']
    HOME_DIR_PATH=ENV['HOME']

    def print_and_execute(command, &block)
        ...
    end
end

Then script1.rb might be like:

#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/commonstuff.rb'
include CommonStuff

puts HOME_DIR_PATH         # Win
print_and_execute "date"   # Win

Or, if you don't want to include the module in your namespace:

#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/commonstuff.rb'

puts CommonStuff::HOME_DIR_PATH         # Win
CommonStuff.print_and_execute "date"   # Win

See also Modules and the Programming Ruby page on modules.

Sarah Vessels
That's pretty much what I did, I have a RubyToolkit module with all the things I need (config file processing, logging, etc etc)
Yoann Le Touche