本文简要介绍ruby语言中 RDoc::Options类 的用法。
RDoc::Options 处理选项的解析和存储
已保存 Options
您可以在 gem 的 .rdoc_options 文件中保存一些选项,例如标记格式。最简单的方法是:
rdoc --markup tomdoc --write-options
这将自动创建文件并用您指定的选项填充它。
以下选项不会被保存,因为它们会干扰用户的偏好或 RDoc 的正常运行:
-
--coverage-report -
--dry-run -
--encoding -
--force-update -
--format -
--pipe -
--quiet -
--template -
--verbose
自定义 Options
生成器可以挂接到 RDoc::Options 以添加 generator-specific 命令行选项。
当在 ARGV 中遇到 --format 时, RDoc 在生成器类上调用::setup_options 以向选项解析器添加额外的选项。自定义生成器的 Options 必须出现在 --format 之后。 rdoc --help 将列出所有已安装生成器的选项。
例子:
class RDoc::Generator::Spellcheck
RDoc::RDoc.add_generator self
def self.setup_options rdoc_options
op = rdoc_options.option_parser
op.on('--spell-dictionary DICTIONARY',
RDoc::Options::Path) do |dictionary|
rdoc_options.spell_dictionary = dictionary
end
end
end
当然,默认情况下 RDoc::Options 不响应 spell_dictionary 所以你需要添加它:
class RDoc::Options
##
# The spell dictionary used by the spell-checking plugin.
attr_accessor :spell_dictionary
end
选项验证器
OptionParser 验证器将验证并转换用户输入值。除了 OptionParser ( String , Integer , Float , TrueClass , FalseClass , Array , Regexp , Date , Time , URI 等)附带的验证器之外, RDoc::Options 还添加了 Path 、 PathArray 和 Template 。
相关用法
- Ruby Option.level用法及代码示例
- Ruby Option.byte用法及代码示例
- Ruby Option.family用法及代码示例
- Ruby OptionParser类用法及代码示例
- Ruby Option.int用法及代码示例
- Ruby Option.new用法及代码示例
- Ruby Option.ipv4_multicast_loop用法及代码示例
- Ruby Option.inspect用法及代码示例
- Ruby Option.bool用法及代码示例
- Ruby Option.to_s用法及代码示例
- Ruby Option.unpack用法及代码示例
- Ruby Option.optname用法及代码示例
- Ruby Option.ipv4_multicast_ttl用法及代码示例
- Ruby OptionParser.reject用法及代码示例
- Ruby Option.data用法及代码示例
- Ruby OptionParser.getopts用法及代码示例
- Ruby OptionParser.accept用法及代码示例
- Ruby Option.linger用法及代码示例
- Ruby Open3.capture3用法及代码示例
- Ruby Open3.capture2用法及代码示例
- Ruby OpenStruct.ostruct[name] =用法及代码示例
- Ruby OpenSSL.fips_mode =用法及代码示例
- Ruby OpenSSL模块用法及代码示例
- Ruby Open3.capture2e用法及代码示例
- Ruby Open3.popen2e用法及代码示例
注:本文由纯净天空筛选整理自ruby-lang.org大神的英文原创作品 Options类。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。
