Creating and Publishing Gems
Best practices: semantic versioning, a CHANGELOG, minimal dependencies, a namespaced error hierarchy, RBS signatures, CI testing across Ruby versions, YARD docs (yard doc), trusted publishing via GitHub Actions.
bundle gem text_tools --test=rspec --ci=github --linter=rubocoptext_tools/
├── lib/
│ ├── text_tools.rb
│ └── text_tools/
│ ├── version.rb
│ └── slugifier.rb
├── sig/text_tools.rbs
├── spec/
├── exe/text_tools # executables
├── text_tools.gemspec
├── Gemfile
├── Rakefile
└── README.md# lib/text_tools.rb
require_relative "text_tools/version"
require_relative "text_tools/slugifier"
module TextTools
class Error < StandardError; end
def self.slugify(text) = Slugifier.new(text).call
end
# text_tools.gemspec
Gem::Specification.new do |spec|
spec.name = "text_tools"
spec.version = TextTools::VERSION
spec.authors = ["Your Name"]
spec.summary = "Text utilities"
spec.license = "MIT"
spec.required_ruby_version = ">= 3.2"
spec.files = Dir["lib/**/*", "exe/*", "README.md", "LICENSE.txt"]
spec.bindir = "exe"
spec.executables = ["text_tools"]
spec.add_dependency "unicode_normalize", "~> 0.1"
spec.metadata["rubygems_mfa_required"] = "true"
endgem build text_tools.gemspec
gem install ./text_tools-0.1.0.gem
gem push text_tools-0.1.0.gem # publish to RubyGems.org (enable MFA!)
bundle exec rake release # tag + build + push