當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Ruby Specification類用法及代碼示例

本文簡要介紹ruby語言中 Gem::Specification類 的用法。

Specification 類包含 gems 的信息。通常在 .gemspec 文件或 Rakefile 中定義,如下所示:

Gem::Specification.new do |s|
  s.name        = 'example'
  s.version     = '0.1.0'
  s.licenses    = ['MIT']
  s.summary     = "This is an example!"
  s.description = "Much longer explanation of the example!"
  s.authors     = ["Ruby Coder"]
  s.email       = 'rubycoder@example.com'
  s.files       = ["lib/example.rb"]
  s.homepage    = 'https://rubygems.org/gems/example'
  s.metadata    = { "source_code_uri" => "https://github.com/example/example" }
end

從RubyGems 2.0 開始, Specification 可以保存任意元數據。有關可以添加到規範中的元數據項的格式和大小限製,請參閱 metadata

相關用法


注:本文由純淨天空篩選整理自ruby-lang.org大神的英文原創作品 Specification類。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。