logo
  • 教程列表
  • SO官方文檔
  • OptionParser
    • 必需和可選的命令列選項
    • 預設值
    • 詳細說明
  1. StackOverflow 文件
  2. Ruby Language 教程
  3. OptionParser
  4. 預設值

預設值

Created: November-22, 2018

使用 OptionsParser,設定預設值非常容易。只需預先填充儲存選項的雜湊:

options = {
  :directory => ENV['HOME']
}

定義解析器時,如果使用者提供值,它將覆蓋預設值:

OptionParser.new do |opts|
  opts.on("-d", "--directory HOME", "Directory to use") do |d|
    options[:directory] = d
  end
end
  • 詳細說明
  • 必需和可選的命令列選項

Copyright © 2018. All right reserved

tastones.com 备案号:鲁ICP备18045372号-1

  • 關於本站
  • 免責聲明