Sha256: feae3dec3d2efb70c2b64a4473e5ccf2e3b76c646b6908ff750a3e7d894d20e1

Contents?: true

Size: 425 Bytes

Versions: 1

Compression:

Stored size: 425 Bytes

Contents

class Range  
  def intersect(other)  
    raise ArgumentError, 'value must be a Range' unless other.kind_of?(Range)  

    new_min = self.cover?(other.min) ? other.min : other.cover?(min) ? min : nil  
    new_max = self.cover?(other.max) ? other.max : other.cover?(max) ? max : nil  

    new_min && new_max ? new_min..new_max : nil  
  end  
  alias_method :intersection, :intersect
  alias_method :&, :intersection  
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sugar-high-0.7.1 lib/sugar-high/range.rb