composite_range is a simple class if you need to deal with more than one range at once.
Add this line to your application's Gemfile:
gem 'composite_range'
And then execute:
$ bundle
Or install it yourself as:
$ gem install composite_range
You can simply create a composite range by passing all ranges that you plan to deal with:
range = CompositeRange.new([1..10, 12..45, 37..98])
If you have some ranges to exclude from the main one:
range = CompositeRange.new(1..20, exclude: [3..5, 9..14])
After creating of instance, you can do the range operations: include?, cover?, begin, end, first, last.
Adding ranges dynamically:
range << (2..12)
or
range[] = (2..12)
Getting range by index:
range[index]
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Added some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request