LoginSignup
9
9

More than 5 years have passed since last update.

Thorでエレガントさを実感する方法

Posted at

思いっきり以下のブログから引用です。詳細はそちらをご覧下さい。ブログ著者の方に感謝!

出展元:mitukiii.jp「Rubyでコマンドラインスクリプト書くならThorが便利そう」」

以下のファイルを作る。

sample
#!/usr/bin/env ruby

require 'rubygems'
require 'thor'

class Sample < Thor
  desc 'hello', 'Hello, World'
  def hello
    puts 'Hello, World!'
  end
end

Sample.start

以下のとおりに使う。

$ chmod +x sample
$ ./sample
Tasks:
  sample hello        # Hello, World
  sample help [TASK]  # Describe available tasks or one specific task

$ ./sample hello
Hello, World!

注意:
ソースと実行結果の関連がわかるように、一部ソースを出展元の内容から書き換えてます。(Worldの後に!がある、無しに差をつけました。)

9
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
9