class OpenEndedRange attr_reader :first, :last def initialize(first, last, exists = {}) exists = { first => true, last => true }.merge(exists) @first, @last, @first_exists, @last_exists = first, last, exists[:first], exists[:last] end def first_exists? @first_exists end def last_exists? @last_exists end def include?(other) case [first_exists?, last_exists?] when [true, true] first <= other && other <= last when [true, false] first <= other when [false, true] other <= last when [false, false] true end end alias_method :===, :include? end