テンプレ おれのテンプレ。class 化して require したただけでは、オプション処理が発動しないようにしている。 require 'optparse' class Test class CLI def parse_options(argv = ARGV) op = OptionParser.new # op がローカル変数なので `define_method` で `usage` を定義しているが、ただのこだわりに過ぎないと言えばその通り self.class.module_eval do define_method(:usage) do |msg = nil| puts op.to_s puts "error: #{msg}" if msg exit 1 end end # default value opts = { boolean: false, string: '', in