用途:指导 Ruby gem 的开发全流程,包括项目结构、测试、代码检查、CI/CD 与发布。适用于处理 .gemspec、Rakefile,或用户询问 gem 结构、RSpec 测试等场景。Rails 应用请改用 rails 技能。
主要能力:提供 gem 标准目录结构(lib 入口、version.rb、spec、sig、CI 工作流、.rubocop.yml、gemspec、Gemfile);gemspec 编写规范,要求指定 required_ruby_version、设置 rubygems_mfa_required 与 metadata URI;RSpec 测试约定(expect 语法、subject、WebMock、SimpleCov 覆盖率≥90%);RuboCop 配置(rubocop-rspec、rubocop-performance、NewCops、行宽 120、方法长度 10);线程安全用 Mutex;CI 使用最新两个稳定 Ruby 小版本矩阵与 ruby/setup-ruby、bundler-cache。
使用方式:常用命令包括 bundle gem my_gem --test=rspec --ci=github --linter=rubocop、bundle install && bundle exec rspec && bundle exec rubocop -A、gem build my_gem.gemspec、gem push my_gem-1.0.0.gem --attestation。提交前须通过 make check && make test-e2e,其中 make check 展开为 bundle exec rubocop、bundle exec rspec、bundle exec bundler-audit check --update。版本需实际查询:ruby -v、cat .ruby-version、curl -s https://endoflife.date/api/ruby.json | jq -r '.[0].latest',并读取 .ruby-version、Gemfile、gemspec 的 required_ruby_version 确定下限,不要凭记忆硬编码。
限制:资料未提供具体收费、平台支持范围或效果数据;详细测试示例、CI 配置、HTTP 客户端模式与发布步骤需参见 references/ruby-patterns.md。