This post originated from an RSS feed registered with Agile Buzz
by Marty Andrews.
Original Post: ruby files as libraries or scripts
Feed Title: Ramblings of the Wry Tradesman
Feed URL: http://www.wrytradesman.com/blog/index.rdf
Feed Description: Marty Andrews talks about the day to day issues he faces as an agile coach on large enterprise applications in Australia.
Include the following snippet at the end of a Ruby file:
if $0 == __FILE__
# do something
end
If you execute the file, the 'do something' block will run, but if you require the file, it won't. That way you can use the file as both a library and a script.