https://github.com/dblock/with-version
Syntax sugar for version checks.
https://github.com/dblock/with-version
Last synced: 9 months ago
JSON representation
Syntax sugar for version checks.
- Host: GitHub
- URL: https://github.com/dblock/with-version
- Owner: dblock
- License: mit
- Created: 2020-01-13T21:26:18.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2020-07-16T14:47:07.000Z (almost 6 years ago)
- Last Synced: 2025-08-26T08:38:14.560Z (10 months ago)
- Language: Ruby
- Size: 14.6 KB
- Stars: 4
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
Awesome Lists containing this project
README
With::Version
==========
[](http://badge.fury.io/rb/with-version)
[](https://travis-ci.org/dblock/with-version)
Syntax sugar for version checks. Inspired by [usage in hashie](https://github.com/hashie/hashie/search?q=with_minimum_ruby&unscoped_q=with_minimum_ruby).
## Usage
### Ruby::Version
Use `with_minimum_ruby` to check against a Ruby version at class load time, instead of runtime.
```ruby
require 'with-version'
class Example
include With::Version::Ruby
with_minimum_ruby '2.4.0' do
# only declared with Ruby 2.4.0 or newer
def dig(*keys)
puts "Digging #{keys.join(', ')} ..."
end
end
end
```
```ruby
# Ruby 2.3.0
undefined method `dig' for # (NoMethodError)
```
```ruby
# Ruby 2.4.0
Digging x, y ...
```
It will automatically handle pre-release versions differently from when using `Gem::Version`, which is something developers often don't consider.
```ruby
Gem::Version.new('2.4.0.pre') >= Gem::Version.new('2.4.0') # false
```
```ruby
require 'with-version'
class Example
include With::Version::Ruby
with_minimum_ruby '2.4.0' do
# also true if RUBY_VERSION = 2.4.0.pre
end
end
```
## Contributing
You're encouraged to contribute to this gem. See [CONTRIBUTING](CONTRIBUTING.md) for details.
## Copyright and License
Copyright (c) 2020, Daniel Doubrovkine and [Contributors](CHANGELOG.md).
This project is licensed under the [MIT License](LICENSE.md).