I find my self doing this alot:
optparse = OptionParser.new do |opts|
options[:directory] = "/tmp/"
opts.on('-d','--dir DIR', String, 'Directory to put the output in.') do |x|
raise "No such directory" unless File.directory?(x)
options[:directory] = x
end
end
It would be nicer if I could specify Dir
or Pathname
instead of String
. Is there a pattern or my ruby-esque way of doing this?