Skip to content

Commit

Permalink
Merge branch 'main' into gh-main
Browse files Browse the repository at this point in the history
  • Loading branch information
pboling committed Jan 17, 2025
2 parents 7867d03 + 5121b60 commit 91e20ed
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,24 @@ MyLib::Version.to_a # => [0, 1, 0]
MyLib::Version.to_h # => { major: 0, minor: 1, patch: 0, pre: "" }
```

### Side benefit
### Side benefit #1

You can reference the DRY version from your gemspec, *and* still get accurate code coverage!

```ruby
# Get the GEMFILE_VERSION without *require* "my_gem/version", for code coverage accuracy
# See: https://github.com/simplecov-ruby/simplecov/issues/557#issuecomment-825171399
load 'lib/my_gem/version.rb'
gem_version = MyGem::Version::VERSION
MyGem::Version.send(:remove_const, :VERSION)

Gem::Specification.new do |spec|
# ...
spec.version = gem_version
end
```

### Side benefit #2

Your `version.rb` file now abides the Ruby convention of directory / path matching the namespace / class!

Expand Down

0 comments on commit 91e20ed

Please sign in to comment.