Sha256: 98a296054043582d9819cee9381b6dc2e090862b6de7166320225503094a22be
Contents?: true
Size: 1.54 KB
Versions: 1
Compression:
Stored size: 1.54 KB
Contents
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 #<Example:0x00007fca9388a8a0> (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).
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
with-version-0.2.0 | README.md |