gemの作成
プロジェクトの作成
code:sh
$ bundle gem weighted_rand
$ git add .
$ git commit -m "Init"
開発環境の整備
Gemfileに必要なgemを追加する。
code:Gemfile
# frozen_string_literal: true
# Specify your gem's dependencies in weighted_rand.gemspec
gemspec
gem "rake", "~> 13.0"
gem "minitest", "~> 5.0"
gemspecファイルの記入。TODOは全て記入しないとだめ。
code:weighted_rand.gemspec
# frozen_string_literal: true
require_relative "lib/weighted_rand/version"
Gem::Specification.new do |spec|
spec.name = "weighted_rand"
spec.version = WeightedRand::VERSION
spec.summary = "Weighted random selection"
spec.description = "This gem provides a method to select a random element from a hash with weights."
spec.license = "MIT"
spec.required_ruby_version = ">= 2.6.0"
# Specify which files should be added to the gem when it is released.
# The git ls-files -z loads the files in the RubyGem that have been added into git.
spec.files = Dir.chdir(File.expand_path(__dir__)) do
git ls-files -z.split("\x0").reject do |f|
(f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
end
end
spec.bindir = "exe"
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
spec.require_paths = "lib" end
VSCodeの設定
code:settings.json
{
"ruby.useLanguageServer": true,
"ruby.useBundler": true,
"ruby.format": "rubocop",
"ruby.lint": {
"rubocop": true
},
"editor.formatOnSave": true
}
}
.ruby-versionの設定。適当なバージョンにする。
code:.ruby-version
3.1.2
依存ライブラリのインストール
code:sh
$ bin/setup
.rubocopの設定
code:.rubocop.yml
AllCops:
TargetRubyVersion: 2.7
DisabledByDefault: true
Exclude:
- "gems/**/*"
NewCops: enable
Bundler:
Enabled: true
Gemspec:
Enabled: true
Lint:
Enabled: true
Style/TrailingCommaInArguments:
EnforcedStyleForMultiline: consistent_comma
Style/StringLiterals:
EnforcedStyle: single_quotes
READMEの編集
TODOを修正していく。とりあえずはUSERNAMEを修正。あとDevelopmentの修正やReleaseの追記もやっとく。USAGEは後でもいいかも。
code:README.md
# WeightedRand
TODO: Delete this and the text above, and describe your gem
## Installation
Add this line to your application's Gemfile:
`ruby
gem 'weighted_rand'
`
And then execute:
$ bundle install
Or install it yourself as:
$ gem install weighted_rand
## Usage
TODO: Write usage instructions here
## Development
After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also r
un bin/console for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org(https://rubygems.org). ## Release
`
bundle exec rake build
git push origin <branch>
bundle exec rake release
`
## Contributing
## License
## Code of Conduct