class that supports set operations on ranges. some of my first ruby code, so be warned.
Ruby
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib
test
README.markdown
Rakefile

README.markdown

RangeSet

The RangeSet library provides the ability to do set operations on ranges. It comprises an extension to the Range class and a new RangeSet class. Supported set operations are union, intersection and subtraction. Does not work well with ranges with excluded endpoints.

# union:
(1..4) | (3..6)   # => 1..6
(1..2) | (3..4)   # => [1..2, 3..4]

# intersection:
(1..2) & (3..4)   # => nil
(1..4) & (3..6)   # => 3..4
RangeSet.new(2..4, 7..9) & (3..8) # => [3..4, 7..8]

# subtraction:
(2..3) - (1..4)   # => nil
(1..4) - (3..5)   # => 1..3
(1..6) - (3..4)   # => [1..3, 4..6]

Source Code

Main repository is at https://github.com/joshsusser/range_set

Contributors