SetOfRanges::Set
is a simple gem that inherits from Set
and allows Range
instances as values. It behaves like Set
except that the add method attempts to merge adjacent and overlapping ranges. It was designed for use with integer values. Insertion of new range values is proportional to the number of existing values in the set.
Add this line to your application's Gemfile:
gem 'set_of_ranges'
And then execute:
$ bundle
Or install it yourself as:
$ gem install set_of_ranges
require 'set_of_ranges'
set = SetOfRanges::Set.new
set << (5..10)
set << (15..20)
set.to_a #=> [5..10, 15..20]
set << (2..6)
set.to_a #=> [2..10, 15..20]
set << (3..9)
set.to_a #=> [2..10, 15..20]
set << (11...12)
set.to_a #=> [2..11, 15..20]
set << (12..14)
set.to_a #=> [2..20]
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request