In Ruby, you can write a class/module such that it can be (a) loaded into an interactive Ruby terminal without actually executing code, or (b) run as a shell script.
For example, given file
puts 'Foo bar'
if __FILE__ == $PROGRAM_NAME
foo = Foo.new
import os, sys
if os.__file__ == sys.argv:
# do stuff
In your example, when you are running a file independantly vs a part of a module, you can do something like this:
if __name__ == "__main__": main()
which will run
main() if the python file is executed independently.
In your example, you would likely want something like this.
class Foo: def bar(self): print 'Foo bar' def main(): foo = Foo() foo.bar() if __name__ == "__main__": main()
I personally like to define a main function as the above example, but could easily just do:
if __name__ == "__main__": foo = Foo() foo.bar()