aboutsummaryrefslogtreecommitdiff
path: root/lib/interval.rb
blob: 0aa787f1be58c9b679a1ae663645c04a8c4ee2ee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
class Interval
  def initialize(min = Float::INFINITY, max = -Float::INFINITY)
    @min = min
    @max = max
  end

  attr_reader :min, :max

  def size
    @max - @min
  end

  def include?(x)
    min <= x && x <= max
  end

  def surround?(x)
    min < x && x < max
  end
end