If you have some sample code in a ruby file that you want to run ONLY when that file is called directly, enclose it in the following if statement.

if __FILE__ == $0
  puts "Print stuff out here to test this file"
end

The __FILE__ is an environment variable that holds the name of the current file. And $0 gives the first argument on the command line. For example, if I ran the file with ruby test.rb, $0 = test.rb. If the code above is in the file test.rb, it would run. If I ran the file ruby test2.rb and test2.rb calls the file test.rb, the code above would not run because $0 = test2.rb.

This is a handy trick to run put some tests at the bottom of your file.