Making An Executable

chikamichi edited this page Aug 2, 2011 · 3 revisions

You may want to make a script as an executable command. To do this with Thor:

  • include the ruby shebang line.
  • require "thor" in your script.
  • define your Thor class.
  • add #{YourThorClassname}.start to the bottom of your script.

Example: mythorcommand.rb

#!/usr/bin/env ruby
require "rubygems" # ruby1.9 doesn't "require" it though
require "thor"

class MyThorCommand < Thor
  desc "foo", "Prints foo"
  def foo
    puts "foo"


Make the script executable:

chmod a+x mythorcommand.rb

Now you can type:

./mythorcommand.rb foo